Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bitwise & with 0xFF

807601Jun 7 2008 — edited Jun 7 2008
Folks, 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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2008
Added on Jun 7 2008
3 comments
669 views