Skip to contentSkip to conversation

Endianness and comparing IP's

DISCUSSION Iain Sandoe 4 participants 4 messages Jan 6, 2001 – Jan 8, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines

/* convert the bytes of a 32-bit integer to little endian */ #define BSWAP32(c) ((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24)

#define BSWAP32(c) \
(((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24))

will work as you expect it too... ;-)

precedence is a funny thing...

Iain.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw

Good catch!

Quoted 10 lines · Iain Sandoe
Quoted 5 lines

/* convert the bytes of a 32-bit integer to little endian */ #define BSWAP32(c) ((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24)

#define BSWAP32(c) \
(((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24))

Quoted 7 lines

will work as you expect it too... ;-)

precedence is a funny thing...

Iain.

--
<><><><><><><><><><><><>
Keith Clayton
[email protected]

"If you don't trust me with your source code,
why should I trust you with my computer?"

GPG key: http://www.jps.net/kclayton/keith_public_key.html
http://www.keyserver.net

GPG fingerprint: 0C47 F1A1 0434 588C 9457 D53F D86A 5449 43F6 09A0

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
In reply to Iain Sandoe
Quoted 11 lines · Iain Sandoe
Quoted 3 lines

/* convert the bytes of a 32-bit integer to little endian */ #define BSWAP32(c) ((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24)

#define BSWAP32(c) \
(((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24))

will work as you expect it too... ;-)

precedence is a funny thing...

Similarly, replace c' by (c)'.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw

Thank you all. The problem has been solved. solution (as per Iain and Geert):

#define BSWAP32(c) ((((c)>>24)&0xff)|(((c)>>8)&0xff00)|(((c)<<8)&0xff0000)|((c)<<24))

thanks again.
alex

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/