fork download
  1. #include <stdio.h>
  2. #include <arpa/inet.h>
  3.  
  4.  
  5. void testFloat() {
  6. float a[] = {1.1, 2.2, 3.3};
  7. unsigned long b[3];
  8. int len = sizeof(a) / sizeof(a[0]);
  9. int i;
  10.  
  11. for (i = 0; i < len; ++i) {
  12. b[i] = htonl(*(unsigned long*)&a[i]);
  13. b[i] = ntohl(b[i]);
  14. a[i] = *(float*)&b[i];
  15. }
  16.  
  17.  
  18. for (i = 0; i < len; ++i) {
  19. printf("%f ", a[i]);
  20. }
  21. printf("\n");
  22.  
  23. }
  24.  
  25. int main(int ac, char **av) {
  26. testFloat();
  27. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
1.100000 2.200000 3.300000