Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
左詰めの 14 ビットの 2 の補数値を含む 2 バイトがあり、それを符号付きの short 値 (-8192 から +8191 の範囲でしょうか?) に変換する必要があります。
それを行うための最速の方法は何ですか?
単純に 4 で割ります。
(右シフトは実装/未定義の動作につながることに注意してください。)
ポータブルソリューション:
short convert(unsigned char hi, unsigned char lo) { int s = (hi << 6) | (lo >> 2); if (s >= 8192) s -= 16384; return s; }