Skip to content

Instantly share code, notes, and snippets.

@lobster1234
Created January 11, 2016 06:47
Show Gist options
  • Save lobster1234/d3d10d7f12f7e25da582 to your computer and use it in GitHub Desktop.
Save lobster1234/d3d10d7f12f7e25da582 to your computer and use it in GitHub Desktop.
Quick and dirty to convert decimal to binary
public static String binary(int input){
StringBuilder builder = new StringBuilder();
int numerator = input;
while(true){
int divisor = numerator/2;
int remainder = numerator%2;
builder.append(remainder+"");
numerator = divisor;
if(divisor==1){
builder.append("1");
break;
}else if(divisor==0){
builder.append("0");
break;
}
}
return builder.reverse().toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment