Originally Posted by
passel
What did you expect?
Your LongToBitString function returns a 32 character string of 0's and 1's, most significant bit first.
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.
For instance, for a double value of 1.0, the 8 bytes in hex are:
3FF0000000000000
The function returns the binary string
0011111111110000000000000000000000000000000000000000000000000000
which is the same thing as the hex.
If you have 2.0 in the double the hex value of the 8 bytes are:
4000000000000000
and the string returned from the function is
0100000000000000000000000000000000000000000000000000000000000000
which is the binary representation of a double with the value of 2.
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.
p.s. Some other examples.
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.
0.1 in a double, in Hex
3FB999999999999A, and in Binary
0011111110111001100110011001100110011001100110011001100110011010
In Hex, it is obvious that the 9999.... 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.
A few examples of numbers that are powers of 2, stored in a double, and what the resulting bit pattern is, in Hex
2.0 = 400000000 = 1 * 2^1
4.0 = 401000000 = 1 * 2^2
8.0 = 402000000 = 1 * 2^3
16.0 = 403000000 = 1 * 2^4
32.0 = 404000000 = 1 * 2^5
What you are seeing above is the incrementing of the exponent 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:
1 = 1
2 = 10
4 = 100
8 = 1000
16 = 10000
32 = 100000
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.
(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.)
A couple of example of integer numbers that are not powers of two. Both 3 and 5 would have a second bit set, i.e. in binary:
3 = 11
5 = 101
You would see that second bit in the floating point representation, i.e. in hex:
3 = 400800000
5 = 401400000
Refer back to the hex double representations above of 2 and 4, to see that 3 and 5 have one additional bit set.
This may still be unclear to you, but I don't intend to beat any more on this subject since you can get more detail on floating point representation by searching for information on the internet.
If this function is not what you want, then you will have to be more specific with examples of what you expect the function to return, as I have no idea if it is not what it currently is doing.