Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. msclr::interop::marshal_context context;
  2. std::string Binary = context.marshal_as<std::string>(textBox3->Text);
  3.  
  4. std::bitset<32> set(Binary);
  5. int HexNumber = set.to_ulong();
  6.  
  7. bool negative = !!(HexNumber & 0x80000000);
  8. int exponent = (HexNumber & 0x7f800000) >> 23;
  9. int sign = negative ? -1 : 1;
  10.  
  11. // Subtract 127 from the exponent
  12. exponent -= 127;
  13.  
  14. // Convert the mantissa into decimal using the
  15. // last 23 bits
  16. int power = -1;
  17. float total = 0.0;
  18. for (int i = 0; i < 23; i++)
  19. {
  20. int c = Binary[i + 9] - '0';
  21. total += (float)c * (float)pow(2.0, power);
  22. power--;
  23. }
  24. total += 1.0;
  25.  
  26. float value = sign * (float)pow(2.0, exponent) * total;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement