Reading double from binary in c

can anyone show how to correctly convert binary represented data to a double value in C. for example, I have 8 unsigned char values ​​that will be converted to a double value (let it be called a buffer). therefore, buffer bit [0] 0 is LSB, and buffer [7] is 7 bits is MSB. Thanks a lot in advance!

+3
source share
2 answers

Just quit think

char buf[8];
double x;
...
x = *((double*) buf);
+3
source

IF : ALL true:

  • Your car is insignificant.
  • On your car sizeof(double) == 8
  • , , ( /8- ).
  • , / .

8 (, "fd" - ):

char bytes[8];
fread(&bytes, 8, 1, fd);
double d = *((double*)bytes);

, , . , , , , , , . - - UTF-8, , .

+4

Source: https://habr.com/ru/post/1758995/


All Articles