fork download
  1. class Main {
  2. public static void main(String[] args) {
  3. int i,j;
  4. for (i=0,j=1; i<32; ++i,j<<=1) {
  5. System.out.printf("0x%08x : 0x%02x\n",j,getByte(j));
  6. }
  7. }
  8. public static byte getByte(int n) {
  9. int x = n;
  10. x |= (x >>> 1);
  11. x |= (x >>> 2);
  12. x |= (x >>> 4);
  13. x |= (x >>> 8);
  14. x |= (x >>> 16);
  15. x -= ((x >>> 1) & 0x55555555);
  16. x = (((x >>> 2) & 0x33333333) + (x & 0x33333333));
  17. x = (((x >>> 4) + x) & 0x0f0f0f0f);
  18. x += (x >>> 8);
  19. x += (x >>> 16);
  20. x &= 0x0000003f;
  21. x = 32-x;
  22. x >>>= 3;
  23. x <<= 3;
  24. return (byte)((n&(0xFF000000>>>x))>>>(24-x));
  25. }
  26. }
Success #stdin #stdout 0.04s 245632KB
stdin
Standard input is empty
stdout
0x00000001 : 0x01
0x00000002 : 0x02
0x00000004 : 0x04
0x00000008 : 0x08
0x00000010 : 0x10
0x00000020 : 0x20
0x00000040 : 0x40
0x00000080 : 0x80
0x00000100 : 0x01
0x00000200 : 0x02
0x00000400 : 0x04
0x00000800 : 0x08
0x00001000 : 0x10
0x00002000 : 0x20
0x00004000 : 0x40
0x00008000 : 0x80
0x00010000 : 0x01
0x00020000 : 0x02
0x00040000 : 0x04
0x00080000 : 0x08
0x00100000 : 0x10
0x00200000 : 0x20
0x00400000 : 0x40
0x00800000 : 0x80
0x01000000 : 0x01
0x02000000 : 0x02
0x04000000 : 0x04
0x08000000 : 0x08
0x10000000 : 0x10
0x20000000 : 0x20
0x40000000 : 0x40
0x80000000 : 0x80