Modify this code to read bytes in the reverse endian?

Posted by ibiza on Stack Overflow See other posts from Stack Overflow or by ibiza
Published on 2010-04-28T03:20:17Z Indexed on 2010/04/28 3:33 UTC
Read the original article Hit count: 247

Filed under:
|

Hi, I have this bit of code which reads an 8 bytes array and converts it to a int64.

I would like to know how to tweak this code so it would work when receiving data represented with the reverse endian...

    protected static long getLong(byte[] b, int off)
    {
        return ((b[off + 7] & 0xFFL) >> 0) +
                ((b[off + 6] & 0xFFL) << 8) +
                ((b[off + 5] & 0xFFL) << 16) +
                ((b[off + 4] & 0xFFL) << 24) +
                ((b[off + 3] & 0xFFL) << 32) +
                ((b[off + 2] & 0xFFL) << 40) +
                ((b[off + 1] & 0xFFL) << 48) +
                (((long) b[off + 0]) << 56);
    }

Thanks for the help!

© Stack Overflow or respective owner

Related posts about c#

Related posts about byte