开发者

Convert 16-bit signed int to 2-bytes?

I got an array which contains signed int data, i need to convert each value in the array to 2 bytes. I am using C# and i tried using BitCo开发者_JAVA技巧nverter.GetBytes(int) but it returns a 4 byte array.


A signed 16-bit value is best represented as a short rather than int - so use BitConverter.GetBytes(short).

However, as an alternative:

byte lowByte = (byte) (value & 0xff);
byte highByte = (byte) ((value >> 8) & 0xff);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜