我已经用Java编写了下面的程序来将长转换为字节。长到字节转换
public class LongtoByte
{
public static void main(String[] args)
{
long a=222;
byte b=(byte)(a & 0xff);
System.out.println("the value of b is" +b);
}
}
问题是我得到结果-34为变量b。
请告诉我如何得到正确的值。我只需要以字节为单位的值。
什么是你期望的“正确的价值”? –
这是正确的值。 –