Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created November 29, 2012 14:11
Show Gist options
  • Save yao2030/4169333 to your computer and use it in GitHub Desktop.
Save yao2030/4169333 to your computer and use it in GitHub Desktop.
public class Binary
{
public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
int v = 1;
while (v <= N/2)
v = v*2;
int n = N;
while (v > 0)
{
if (n < v) { System.out.print(0);}
else { System.out.print(1); n -= v;}
v = v/2;
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment