How are integers cast to bytes in Java?

后端 未结 8 1214
我在风中等你
我在风中等你 2020-11-27 21:02

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

8条回答
  •  悲&欢浪女
    2020-11-27 21:44

    or does it just directly copy the last 8 bits of the integer

    yes, this is the way this casting works

提交回复
热议问题