home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / byteord < prev    next >
Text File  |  1989-12-04  |  2KB  |  63 lines

  1. Newsgroups: comp.sources.misc
  2. organization: The Johns Hopkins University - HCF
  3. subject: v09i043: Byteord:  simple program to determine byte order
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: gwollman%JHUNIX.BITNET@JHMAIL.HCF.JHU.EDU
  6.  
  7. Posting-number: Volume 9, Issue 43
  8. Submitted-by: gwollman%JHUNIX.BITNET@JHMAIL.HCF.JHU.EDU
  9. Archive-name: byteord
  10.  
  11. Here is a short program which has exactly one purpose:  it tells you
  12. what byte-order your machine uses.  You can probably look this up in a
  13. manual, but it's nice to have a program that anyone can use, to tell
  14. them what the order is.
  15. This is useful for programs, such as the recently posted Unzip,
  16. which need to know the byte order before compilation.
  17.  
  18. --------cut here--------------
  19. #! /bin/sh
  20. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  21. # Contents:  byteord.c
  22. echo extracting 'byteord.c'
  23. if test -f 'byteord.c' -a -z "$1"; then echo Not overwriting 'byteord.c'; else
  24. sed 's/^X//' << \EOF > 'byteord.c'
  25. Xextern int printf();
  26. X#define LONG_VAL (long)0x12345678
  27. X#define I_LONG_L (short)0x5678
  28. X#define SHORT_VAL  (short)0xcdae
  29. X#define I_SHORT_L  (char)0xae
  30. X
  31. X
  32. Xlong something = LONG_VAL;
  33. Xshort sth_else = SHORT_VAL;
  34. X
  35. Xmain() {
  36. X        char *p = (char *)&sth_else;
  37. X    short *p2 = (short *)&something;
  38. X
  39. X    printf("Your byte order is: ");
  40. X    if(*p==I_SHORT_L)
  41. X        printf("LSB first (Intel).\n");
  42. X    else
  43. X        printf("MSB first (non-Intel).\n");
  44. X    printf("Your word [16-bit] order is: ");
  45. X    if(*p2==I_LONG_L)
  46. X        printf("LSW first (Intel).\n");
  47. X    else
  48. X        printf("MSW first (non-Intel).\n");
  49. X    printf("Evidence: %02x (char) %04x (short)\n",
  50. X        (unsigned short)*p,*p2);
  51. X}
  52. EOF
  53. chars=`wc -c < 'byteord.c'`
  54. if test $chars !=      634; then echo 'byteord.c' is $chars characters, should be      634 characters!; fi
  55. fi
  56. exit 0
  57. -- 
  58. |An intellectual is a man who can't do arithmetic with his shoes on, and is  |
  59. |is proud of the lack.                          -Jubal Harshaw               |
  60.    Garrett A. Wollman, Box 2289, JHU, 34th and Charles, Baltimore MD 21218
  61. #include <disclaimer.h>               /* +1 301 338 5792 */
  62.  
  63.