|
|
1.1 ! root 1: ! 2: ! 3: swab() General Function swab() ! 4: ! 5: ! 6: ! 7: ! 8: Swap a pair of bytes ! 9: ! 10: vvooiidd sswwaabb(_s_r_c, _d_e_s_t, _n_b) cchhaarr *_s_r_c, *_d_e_s_t; uunnssiiggnneedd _n_b; ! 11: ! 12: The ordering of bytes within a word differs from machine to ! 13: machine. This may cause problems when moving binary data between ! 14: machines. swab interchanges each pair of bytes in the array src ! 15: that is n bytes long, and places the result into the array dest. ! 16: The length nb should be an even number, or the last byte will not ! 17: be touched. src and dest may be the same place. ! 18: ! 19: ***** Example ***** ! 20: ! 21: This example prompts for an integer; it then prints the integer ! 22: both as you entered it, and as it appears with its bytes swapped. ! 23: ! 24: ! 25: #include <stdio.h> ! 26: ! 27: main() ! 28: { ! 29: int word; ! 30: ! 31: ! 32: ! 33: printf("Enter an integer: \n"); ! 34: scanf("%d", &word); ! 35: printf("The word is 0x%x\n", word); ! 36: swab(&word, &word, 2); ! 37: printf("The word with bytes swapped is 0x%x\n", word); ! 38: } ! 39: ! 40: ! 41: ***** See Also ***** ! 42: ! 43: dd, canon.h, general functions ! 44: ! 45: ! 46: ! 47: ! 48: ! 49: ! 50: ! 51: ! 52: ! 53: ! 54: ! 55: ! 56: ! 57: ! 58: ! 59: ! 60: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.