Convert double value to binary value

How can I convert a double value to a binary value.

I have some value similar to this below 125252525235558554452221545332224587265. I want to convert it to binary format. So I save it in double, and then try to convert to binary (1 and 0). I am using C # .net

+5
source share
5 answers

Well, you did not specify the platform or which binary value you are interested in, but in .NET there BitConverter.DoubleToInt64Bits, which allows you to easily get the IEEE 754 bit making up the value.

In Java there is Double.doubleToLongBitsone that does the same.

, , "125252525235558554452221545332224587265", , .

+11

C , , , union:

int i;
union {
 double x;
 unsigned char byte[sizeof (double)];
} converter;

converter.x = 5.5555555555556e18;

for(i = 0; i < sizeof converter.byte; i++)
  printf("%02x", converter.byte[i]);

main() , - :

~/src> gcc -o floatbits floatbits.c
~/src> ./floatbits
ba b5 f6 15 53 46 d3 43

, , , endianness. Linux-, Sempron, .. endian.

+6

, , .

, , - , . ++:

double f = atof ("5.5555555555556E18");
unsigned char  *b = (unsigned char *) &f;
for (int j = 0; j < 8;  ++j)
    printf (" %02x", b [j]);
0

. , . , , . int, .

, , ... , BigEndian/LittleEndian.

0

( ) .

# Decimal:

79,228,162,514,264,337,593,543,950,335 79,228,162,514,264,337,593,543,950,335. , . Decimal . , - . , 0.999999999999999999999999999999, 1.

, , , . ints: http://sourceforge.net/projects/cpp-bigint/, ++.

-1

All Articles