fork download
  1. class BitwiseTest {
  2. public static void main(String[] args) {
  3. byte msb, lsb;
  4. short total;
  5.  
  6. msb = 0x73;
  7. lsb = (byte)0xFF;
  8. System.out.println(String.format("MSB: %X; LSB: %X",
  9. msb, lsb));
  10.  
  11. total = (short)((msb << 8) | lsb);
  12.  
  13. System.out.println(String.format("Total: %X", total));
  14. System.out.println(String.format("Left shift: %X After OR: %X",
  15. (short)(msb << 8), (short)((msb << 8) | lsb)));
  16.  
  17. if(total != 0x73FF)
  18. System.out.println("wtf.");
  19. else if(total == 0xFFFF)
  20. System.out.println("This is wrong.");
  21. }
  22. }
  23.  
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
MSB: 73; LSB: FF
Total: FFFF
Left shift: 7300 After OR: FFFF
wtf.