开发者

How do I split a short into its two bytes?

开发者 https://www.devze.com 2023-01-02 04:11 出处:网络
I have to split up a short into its two bytes. They have to be in Network orde开发者_如何学运维r.

I have to split up a short into its two bytes. They have to be in Network orde开发者_如何学运维r.

I need that for a small server telling the current size of the rest packet's data.

List<byte> o = new List<byte>();
o.Add(0x03);
// here this short
o.AddRange(MapData);
o.Add(0xFF);
Send(o);


Use IPAddress.HostToNetworkOrder. You can then use GetBytes or bit manipulation to access the actual bytes.


You could use the GetBytes method:

short someShortValue = 25;
byte[] bytes = BitConverter.GetBytes(someShortValue);
0

精彩评论

暂无评论...
验证码 换一张
取 消