我需要输入成对的字节并输出短路,并输入短路并输出成对的字节。以下是我为此目的设计的功能:
static short ToShort(short byte1, short byte2)
{
short number = (short)byte2;
number <<= 4;
number += (short)byte1;
return number;
}
static void FromShort(short number, out byte byte1, out byte byte2)
{
byte byte2 = (byte)(number >> 4);
short tempByte = (short)byte2 << 4;
byte byte1 = (byte)(number - tempByte);
}
我认为这是正确的,但我不确定。如果这不是正确的做法,那是什么?有没有办法在框架中做到这一点?