Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created October 11, 2008 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya2000/16208 to your computer and use it in GitHub Desktop.
Save miya2000/16208 to your computer and use it in GitHub Desktop.
package test01;
public class BinaryDumpTest {
public static void main(String[] args) {
System.out.print("Integer.MAX_VALUE : ");
binaryDump(Integer.MAX_VALUE);
System.out.print("Integer.MIN_VALUE : ");
binaryDump(Integer.MIN_VALUE);
System.out.print("-1 : ");
binaryDump(-1);
for (int i = 1; i <= 32; i++){
System.out.printf("-1 >> %2d: ", i);
binaryDump(-1 >> i);
}
for (int i = 1; i <= 32; i++){
System.out.printf("-1 >>> %2d : ", i);
binaryDump(-1 >>> i);
}
}
static void binaryDump(int n) {
String s = Integer.toBinaryString(n);
s = String.format("%32s", s);
s = s.replaceAll(" ", "0");
s = s.replaceAll("(\\d{8})", "$1 ");
System.out.println(s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment