fork download
  1. #include <stdio.h>
  2.  
  3. #define BYTEBIN "%d%d%d%d%d%d%d%d"
  4. #define BYTE2BIN(byte) \
  5.   (byte & 0x80 ? 1 : 0), \
  6.   (byte & 0x40 ? 1 : 0), \
  7.   (byte & 0x20 ? 1 : 0), \
  8.   (byte & 0x10 ? 1 : 0), \
  9.   (byte & 0x08 ? 1 : 0), \
  10.   (byte & 0x04 ? 1 : 0), \
  11.   (byte & 0x02 ? 1 : 0), \
  12.   (byte & 0x01 ? 1 : 0)
  13.  
  14. int main(void) {
  15. float fa = 0.999999f;
  16.  
  17. unsigned int *ia = (unsigned int*)&fa;
  18. unsigned char *ba = (unsigned char*)&fa;
  19. printf("float %f in binary: "BYTEBIN" "BYTEBIN" "BYTEBIN" "BYTEBIN"\n",
  20. fa, BYTE2BIN(ba[3]), BYTE2BIN(ba[2]), BYTE2BIN(ba[1]), BYTE2BIN(ba[0]));
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
float 0.999999 in binary: 00111111 01111111 11111111 11101111