我正在使用这种方法(来自此处 http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midispec/wheel.htm)读取 midi 音调轮消息,该方法将 2 个十六进制字节组合成一个 14 位无符号短整数。它工作得很好,但现在我正在尝试发送需要采用 2 字节十六进制格式的音调轮消息。有谁知道如何反转此方法,以便它采用像 12401 这样的整数并返回两个字节?
unsigned short CombineBytes(unsigned char First, unsigned char Second)
{
unsigned short _14bit;
_14bit = (unsigned short)Second;
_14bit <<= 7;
_14bit |= (unsigned short)First;
return(_14bit);
}
这是我的错误尝试:
unsigned char CreateBytes(unsigned short value)
{
unsigned char First;
unsigned char Second;
unsigned char FullValue;
FullValue = (unsigned short)value;
First = FullValue;
First >>= 7;
Second |= (unsigned short) value;
return(First, Second);
}
first = (combined & 0x3f80) >> 7; // 0b11111110000000
second = (combined & 0x007f); // 0b00000001111111
我是一名优秀的程序员,十分优秀!