Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 有人能改变这种方法吗?_C_Bit Manipulation - Fatal编程技术网

C 有人能改变这种方法吗?

C 有人能改变这种方法吗?,c,bit-manipulation,C,Bit Manipulation,我用这个方法(从这里)读取midi pitchwheel消息,它将2个十六进制字节组合成一个14位无符号的短字符。它工作得很好,但现在我正试图发送pitchwheel消息,需要在2字节十六进制格式。有人知道如何反转此方法,使其接受12401这样的整数并返回两个字节吗 unsigned short CombineBytes(unsigned char First, unsigned char Second) { unsigned short _14bit; _14bit = (un

我用这个方法(从这里)读取midi pitchwheel消息,它将2个十六进制字节组合成一个14位无符号的短字符。它工作得很好,但现在我正试图发送pitchwheel消息,需要在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