Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // need to include math.h!!
- float byteToFloat(char a, char b, char c, char d) {
- int bin = (d << 24 | c << 16 | b << 8 | a);
- char sign = (((bin & 0x80000000) >> 31) == 1)?-1:1;
- float exp = pow(2.0f, ((bin & 0x7F800000) >> 23) - 127);
- float mant = 1.0f;
- for (int i = 22; i >= 0; i--) {
- if ((bin >> i) & 1)
- mant += 1.0f / pow(2.0f, 23 - i);
- }
- return sign * exp * mant;
- }
Advertisement
Add Comment
Please, Sign In to add comment