首先我们要都知道, &表示按位与,只有两个位同时为1,才能得到1, 0x代表16进制数,0xff表示的数二进制1111 1111 占一个字节.和其进行&操作的数,最低8位,不会发生变化.下面着重来说说&0xff都有哪些应用:1.只是为了取得低八位通常配合移位操作符>>使用例如:java socket通信中基于长度的成帧方法中,如果发送的信息长度小于65535字节,长度信息的字节定义为两个字节长度。这时候将两个字节长的长度信息,以Big-Endian的方式写到内存中out.write((message.length>>8)&0xff);//取高八位写入地址out.write(message.length&0xff);//取低八位写入高地址中例如,有个数字 0x1234,如果只想将低8位写入到内存中 0x1234&0xff0x1234 表示为二进制 00010010001101000xff 表示为二进制 11111111两个数做与操作,显然将0xff补充到16位,就是高位补0此时0xff 为 0000000011111111与操作 1&0 =0 1&1 =1 这样
Norman1z