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.
CI では、auint8_tを 0 ~ 255 から 0 ~ 31にスケーリングする必要があります
uint8_t
これを均等に行うための最良の方法は何ですか?
8 ビットから 5 ビットにスケーリングしようとしている場合は、3 ビット シフトを行うことができます。
uint8_t scaled = (uint8_t)(original >> 3);
これにより、下位 3 ビットがドロップされます。
簡単な乗算と除算を使用できます。
uint8_t scaled = (uint8_t)(((uint32_t)original * 32U) / 256U);