110,536
社区成员
发帖
与我相关
我的任务
分享
int a = 65535;
Console.WriteLine(BitConverter.GetBytes(a).Length); //4
Console.WriteLine(BitConverter.GetBytes((Int16)a).Length); //2
既然你已经确认他小于 65536 了,那你就告诉 C#:这是一个 Int16 的数,而不是让 C# 去猜你的意图
UInt16 originalData = 65535;
byte[] newByte = BitConverter.GetBytes(originalData);
foreach(byte b in newByte)
{
MessageBox.Show(b.ToString());
}
输出:
255
255
int x = 65535;
var r = BitConverter.GetBytes(x).Take(2).Reverse().ToArray();
int x = 65533;
var s =x.ToString("x2");