fork download
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. union Double{
  5. double d;
  6. unsigned char c[sizeof(double)];
  7. } ;
  8.  
  9. void PrintBinRepresention(union Double ud){
  10. int i,j;
  11. for(i =0;i<sizeof(double);++i){
  12. printf("Byte %d = ",i);
  13. for(j =CHAR_BIT-1;j>=0;--j){
  14. printf("%hhx",(ud.c[i]>>j)&0x1);
  15. }
  16. printf("\n");
  17. }
  18. printf("\n");
  19. }
  20.  
  21. int main() {
  22. // your code goes here
  23.  
  24. union Double ud;
  25. ud.d = 6;
  26. PrintBinRepresention(ud);
  27. ud.c[(1*sizeof(short)/sizeof(unsigned char))] = 6;
  28. PrintBinRepresention(ud);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
Byte 0 = 00000000
Byte 1 = 00000000
Byte 2 = 00000000
Byte 3 = 00000000
Byte 4 = 00000000
Byte 5 = 00000000
Byte 6 = 00011000
Byte 7 = 01000000

Byte 0 = 00000000
Byte 1 = 00000000
Byte 2 = 00000110
Byte 3 = 00000000
Byte 4 = 00000000
Byte 5 = 00000000
Byte 6 = 00011000
Byte 7 = 01000000