Skip to content

Instantly share code, notes, and snippets.

@doridori doridori/ex1.java
Last active Aug 29, 2015

Embed
What would you like to do?
Java: Bitshifting Bytes post code samples
byte aByte = -112; //0b1001_0000
byte bByte = (byte) (aByte >> 4); //would expect 0b1111_1001 (-7)
System.out.println(bByte); //-7
byte cByte = (byte) (aByte >>> 4); //would expect 0b0000_1001 (9)
System.out.println(cByte); //-7
byte dByte = (byte) ((aByte & 0xFF) >>> 4); //we get 0b0000_1001 (9)
System.out.println(dByte); //9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.