C#操作高低位

Posted surroundsea

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); 

以上是关于C#操作高低位的主要内容,如果未能解决你的问题,请参考以下文章