How do you make two floats out of 104-bits?
Posted: Sun Sep 12, 2010 6:18 am
Hi everybody,
I am playing around with maths, bits and such. Now for academic purposes, I want to know how to convert some data that is exactly 104-bits (or in other words 13 bytes) to two PHP floats. I need it to be perfect and not lose information. So, the function should be capable of doing exactly two floats with 2^52 different float values out of the 104-bits.
PHP uses http://en.wikipedia.org/wiki/Double_pre ... int_format and thus a float can have 2^52 different possibilities.
If it were 2^56 and not 2^52, I could just substr() the first 7 bytes, loop them and sum with ord(), and divide the final sum by 2^56 and have my float. However, the precision is 2^52, so I need to get first 7 bytes and rid of the 4-bits and use them for the second float and what I exactly need to do is a bit unclear to me. Help?
I am playing around with maths, bits and such. Now for academic purposes, I want to know how to convert some data that is exactly 104-bits (or in other words 13 bytes) to two PHP floats. I need it to be perfect and not lose information. So, the function should be capable of doing exactly two floats with 2^52 different float values out of the 104-bits.
PHP uses http://en.wikipedia.org/wiki/Double_pre ... int_format and thus a float can have 2^52 different possibilities.
If it were 2^56 and not 2^52, I could just substr() the first 7 bytes, loop them and sum with ord(), and divide the final sum by 2^56 and have my float. However, the precision is 2^52, so I need to get first 7 bytes and rid of the 4-bits and use them for the second float and what I exactly need to do is a bit unclear to me. Help?