Number System Conversions in C++
A posting which I will probably update from time to time that summarizes the conversion functions I encounter in C++. Hope others will find this useful too. 32-bit IEEE 754 floating point value to binary string [code language="cpp"] std::string GetBinary32( float value ) { union { float input; // assumes sizeof(float) == sizeof(int) int output; } data; data.input = value; std::bitset<sizeof(float) * CHAR_BIT> bits(data.output); std::string mystring = bits.to_string<char, std::char_traits<char>, std::allocator<char> >(); return mystring; } [/code] 32-bit IEEE 754 binary string to floating point value [code language="cpp"] float GetFloat32( std::string Binary ) { int HexNumber = Binary2Hex( Binary ); bool negative = !!(HexNumber & 0x80000000); int exponent = (HexNumber & 0x7f800000) >> 23; int sign = negative ? -1...