![]() ![]() Refer back to the hex double representations above of 2 and 4, to see that 3 and 5 have one additional bit set. You would see that second bit in the floating point representation, i.e. Both 3 and 5 would have a second bit set, i.e. (I'm describing the IEEE standard representation of Floating Point, which most machines use these days, but there are other representations and those may or may not have an implied "1" as the MSB of the mantissa.)Ī couple of example of integer numbers that are not powers of two. That MSB "1", will not be part of the floating point number, it is "implied" to exist as one additional bit "above" the most significant bit of the mantissa portion of the floating point number. Since the most significant bit of the mantissa is always 1, the 1 is not actually stored, to give an extra bit of precision in the floating point format, so you won't see that "1" in the above numbers since they are all integer powers of 2, and integer powers of two would have only 1 bit set,i.e, as an integer type, the first few powers of two in binary are: ![]() What you are seeing above is the incrementing of the exponent portion of the floating point number. would go on forever, but since you only have 64 bits, the last bit is rounded up, so the last Hex digit is A, instead of 9.Ī few examples of numbers that are powers of 2, stored in a double, and what the resulting bit pattern is, in Hex Since numbers such as 0.1 can't be represented exactly in Floating point (it is an infinite series of repeating binary digits), it will give a more interesting pattern than the Floating point values holding simple integer values, as above.Ġ011111110111001100110011001100110011001100110011001100110011010 I made the assumption that what your supplied function returned, a string of 32 bits represented by a string of 0's and 1's, was what you wanted for a double, of course a double is 64 bits, not 32. Which is the binary representation of a double with the value of 2. The DoubleToString simply copies the 8 bytes of a double into two Longs, and then calls your function twice, passing the Most Significant half first and concatenates the lower half to that, so you get a 64 character string of 0's and 1's, most significant bit first.įor instance, for a double value of 1.0, the 8 bytes in hex are:Ġ011111111110000000000000000000000000000000000000000000000000000 Your LongToBitString function returns a 32 character string of 0's and 1's, most significant bit first. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |