C/C++ - Convert 24-bit signed integer to float

前端 未结 7 2148
野的像风
野的像风 2021-01-12 20:27

I\'m programming in C++. I need to convert a 24-bit signed integer (stored in a 3-byte array) to float (normalizing to [-1.0,1.0]).

The platform is MSVC++ on x86 (wh

7条回答
  •  南方客
    南方客 (楼主)
    2021-01-12 21:03

    Looks like you're treating it as an 24-bit unsigned integer. If the most significant bit is 1, you need to make i negative by setting the remaining 8 bits to 1 as well.

提交回复
热议问题