|
|
coherent
swab() General Function swab()
Swap a pair of bytes
vvooiidd sswwaabb(_s_r_c, _d_e_s_t, _n_b) cchhaarr *_s_r_c, *_d_e_s_t; uunnssiiggnneedd _n_b;
The ordering of bytes within a word differs from machine to
machine. This may cause problems when moving binary data between
machines. swab interchanges each pair of bytes in the array src
that is n bytes long, and places the result into the array dest.
The length nb should be an even number, or the last byte will not
be touched. src and dest may be the same place.
***** Example *****
This example prompts for an integer; it then prints the integer
both as you entered it, and as it appears with its bytes swapped.
#include <stdio.h>
main()
{
int word;
printf("Enter an integer: \n");
scanf("%d", &word);
printf("The word is 0x%x\n", word);
swab(&word, &word, 2);
printf("The word with bytes swapped is 0x%x\n", word);
}
***** See Also *****
dd, canon.h, general functions
COHERENT Lexicon Page 1
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.