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