C#操作高低位

1.int32占4个字节

int data=2147483647;
byte[] byte4 =new byte[4];
byte4 = BitConverter.GetBytes(data);//结果逆序

2.int16占2个字节:

int data=32767;
byte high=Convert.ToByte((data >> 8) & 0x00ff); //位运算:右移8位
byte low=Convert.ToByte(data & 0x00ff);         //去掉高位

3.十六进制(byte[])转int类型

byte[] bytes={0x00,0x00,0x00,0x00};//逆序转换
int data=BitConverter.ToInt32(bytes.Reverse().ToArray(),0); 

猜你喜欢

转载自www.cnblogs.com/SurroundSea/p/10922885.html