开发者

How do I split a short into its two bytes?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜