Here's some C code which will break the ieee754 double into it's parts for you:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int main(int argc, char* argv[]) {
double d = 8796093022208.0; /* this is 2^43 so the mantissa will be 0 */
uint64_t n = *(uint64_t*)(&d);
int sign = (n >> 63); /* sign is the top bit */
int exponent = (n >> 52) & 0x07ff; /* exponent is 11 bits starting at
* bit 52 */
int exp_value = exponent - 1023; /* subtract 1023 to get the 'real'
* value of the exponent */
uint64_t mantissa = (n & 0x07ffffffffffffLL); /* the mantissa is the
* bottom 52 bits */
printf("double: %lf\n", d);
printf("bits: ");
int i;
for(i = 63; i >= 0; --i) {
printf("%c", (n >> i) & 0x1 ? '1' : '0');
}
printf("\n");
printf("sign: %c\n", sign ? '-' : '+');
printf("exponent: 0x%03x (%d)\n", exponent, exp_value);
printf("mantissa: 0x%llx (%lld)\n", mantissa, mantissa);
return 0;
}
Bookmarks