How are integers casted to bytes in Java?

Posted by helixed on Stack Overflow See other posts from Stack Overflow or by helixed
Published on 2010-03-16T22:03:49Z Indexed on 2010/03/16 22:11 UTC
Read the original article Hit count: 443

Filed under:
|
|
|

I know Java doesn't allow unsigned types, so I was wondering how it casts an integer to a byte. Say I have an integer a with a value of 255 and I cast the integer to a byte. Is the value represented in the byte 11111111? In other words, is the value treated more as a signed 8 bit integer, or does it just directly copy the last 8 bits of the integer?

Thanks,

helixed

© Stack Overflow or respective owner

Related posts about java

Related posts about cast