Unsigned Bytes in Java -


Bytes in Java are signed by default. I look at other posts, which is a sort of workaround for an unsigned byte: int num = (int) cutting & amp; 0xFF

Would anyone explain to me why this works and changes a signed byte to an unsigned byte and its associated integer? ANDing Results in the same byte with a byte 11111111 - correct?

A. Typecast has a higher priority than the and operator For the first time, casting an int, and then ending all the high-order bits set up to make a mask, which includes the two-digit "sign bit" of Java usage, in which you can only use the positive value Is left with the original byte example:

  let's by x = 11111111 = -1 again (int) x = 1111111111111111111111111 1111111 and X & amp; 0xFF = 00000000 00000000 0000000011111111 = 255   

And you have effectively removed the signature from the original byte.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -