

swab()                   General Function                  swab()




Swap a pair of bytes

vvooiidd sswwaabb(_s_r_c, _d_e_s_t, _n_b) cchhaarr *_s_r_c, *_d_e_s_t; uunnssiiggnneedd _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


