Byte Order Swapping Function

KennyTM~ kennytm at gmail.com
Sun Jul 17 00:31:36 PDT 2011


On Jul 17, 11 05:51, Jonathan M Davis wrote:
> On Saturday 16 July 2011 15:38:29 Andrei Alexandrescu wrote:
>> Just paste the code here.
>
> This is what I have at the moment:
>
> import core.bitop;
>
[snip]
>
> private T swapEndianImpl(T)(T val)
>      if(is(Unqual!T == ulong))
> {
>      return ((val&  0xff00000000000000UL)>>  56) |
>             ((val&  0x00ff000000000000UL)>>  40) |
>             ((val&  0x0000ff0000000000UL)>>  24) |
>             ((val&  0x000000ff00000000UL)>>  8) |
>             ((val&  0x00000000ff000000UL)<<  8) |
>             ((val&  0x0000000000ff0000UL)<<  24) |
>             ((val&  0x000000000000ff00UL)<<  40) |
>             ((val&  0x00000000000000ffUL)<<  56);
> }

Why not just 'bswap' the two uint parts?

>
[snip]



More information about the Digitalmars-d mailing list