Boost logo

Boost :

From: Borgerding, Mark A. (MarkAB_at_[hidden])
Date: 2000-03-10 17:18:53

> -----Original Message-----
> From: Marco Manfredini [mailto:marco_at_[hidden]]
> Sent: Friday, March 10, 2000 4:37 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: endian handling classes
> Heeee. You stole it from me :-)
> No, honestly, the trick works very good for me!

Alas, I thought it might not be new. Is your version on boost? I looked but
did not see anything there. I would be interested in seeing your
implementation. Can you send it to the group?

> In my code, I swapped the endians with unions, I think it
> makes it easier to
> see, what actually happens:
> static inline unsigned long endswap (unsigned long v)
> {
> union { unsigned long x; unsigned char b[4]; } s,d;
> s.x=v;
> d.b[0] = s.b[3];
> d.b[1] = s.b[2];
> d.b[2] = s.b[1];
> d.b[3] = s.b[0];
> return d.x;
> }

That does seem a bit easier to understand.
There seems to be a bit of a difference performance wise, though. The union
version takes about 10% longer on my machine.

   uint32 numIts = 1 << 20;
   for (volatile uint32 i=0;i<numIts;++i)
        uint32 n = reverse_bytes(i);
      i = reverse_bytes(n);

> One point: If I'm not utterly wrong, then IEEE's (though hard
> to believe)
> have a big and a little endian representation. Does someone
> knows more?

I believe you are correct. But I don't know where one could find
documentation about it.

If IEEE floating point types are simply reversed bytes on different
machines, then I don't see why these template classes wouldn't work for them

Boost list run by bdawes at, gregod at, cpdaniel at, john at