Subject: [Dev] byte swapper

From: Michael Mueller <[email-masked]>
Date: Tue, 28 May 2002 23:00:24 -0400

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?
TIA,
-- 
Mike Mueller
www.ss7box.com

---

From: Brent Verner <[email-masked]>
Date: 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

---

From: Ed Hill <[email-masked]>
Date: 28 May 2002 21:29:31 -0600

> lurking about, or shall I be forced to write yet another?

Hi Mike,

I've used these.

hth,
Ed

#ifdef LITTLE_ENDIAN

/* Little-endian architectures need byte-swapping. */
#define sws(x) (((x >> 8) & 0x00ff) | ((x << 8) & 0xff00))
#define swl(x) (sws(x >> 16) | (sws(x) << 16))
#define swap_short(x) (x = sws(x))
#define swap_long(x) (x = swl(x))

#else

/* Big-endian architectures don't need byte-swapping. */
#define sws(x) (x)
#define swl(x) (x)
#define swap_short(x) (x = sws(x))
#define swap_long(x) (x = swl(x))

#endif

-- 
Edward H. Hill III, PhD    |  Email:       [email-masked], [email-masked]
Post-Doctoral Researcher   |  URLs:        http://www.eh3.com
Division of ESE            |   http://wasser.mines.edu/people/edhill.php
Colorado School of Mines   |  Phone:       303-273-3483
Golden, CO  80401          |  Fax:         303-273-3311
Key fingerprint = 5BDE 4DA1 66BE 4F7B BC17  3A0C 932B 7266 1E76 F123

---

From: Michael Mueller <[email-masked]>
Date: Wed, 29 May 2002 00:19:52 -0400

Thanks, Brent and Ed.  That helped for sure.

-- 
Mike Mueller
www.ss7box.com

---

From: [email-masked] (John Beimler)
Date: Wed, 29 May 2002 14:10:22 -0400

> lurking about, or shall I be forced to write yet another?

how about dd?  Check out the swab keyword.

Peace

john

---

From: "Andrew C. Oliver" <[email-masked]>
Date: Wed, 29 May 2002 14:18:47 -0400

Hi,

Has anyone done any work on the internals of GCC.  Specifically language 
front-ends?  I'm working on creaing a GCC front end for 
http://www.digitalmars/d.  The front end code for the compiler has been 
released GPL/Artisitic, its just a matter of porting it to GCC.

I've yet to find a working example of the "toy" language referred to in 
the GCC docs, that works with any defined version of GCC.  (So far I 
grab the version of Toy that says its for 3.0 and it turns out not to 
work!  Frustrating!).

Anyone with front end experience that might be able to give me a few 
pointers (pun intended)?

-Andy