[Dev] byte swapper

Brent Verner dev@trilug.org
Tue, 28 May 2002 23:22:17 -0400


[2002-05-28 23:00] Michael Mueller said:
| Is there a byte swapper for big-to-little, and vice-versa, endian interchange 
| lurking about, or shall I be forced to write yet another?

on (recent?) glibc systems, try

#include <netinet/in.h>
uint32_t flipped = __bswap_32(uint32_t_input)
uint16_t flipped = __bswap_16(uint16_t_input)

not sure if *bsd have an analogous function, but if portability is
paramount, you might have to roll your own.

hth.
  b

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman