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);