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);
精彩评论