Bitwise & with 0xFF
807601Jun 7 2008 — edited Jun 7 2008Folks, Looking at a piece of code, didn't understand why do we need to do a bitwise & with 0xFF.
StringBuffer sb = new StringBuffer("F1");
short hexNum = Short.parseShort(sb.toString(), 16);
b[bufIdx] = (byte) (*hexNum & 0xFF*);
As we are casting it to byte, the upper byte would be truncated anyways? If I don't get it right, can someone please explain the logic?
TIA!