Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- msclr::interop::marshal_context context;
- std::string Binary = context.marshal_as<std::string>(textBox3->Text);
- std::bitset<32> set(Binary);
- int HexNumber = set.to_ulong();
- bool negative = !!(HexNumber & 0x80000000);
- int exponent = (HexNumber & 0x7f800000) >> 23;
- int sign = negative ? -1 : 1;
- // Subtract 127 from the exponent
- exponent -= 127;
- // Convert the mantissa into decimal using the
- // last 23 bits
- int power = -1;
- float total = 0.0;
- for (int i = 0; i < 23; i++)
- {
- int c = Binary[i + 9] - '0';
- total += (float)c * (float)pow(2.0, power);
- power--;
- }
- total += 1.0;
- float value = sign * (float)pow(2.0, exponent) * total;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement