c# - Modify this code to read bytes in the reverse endian? -


i have bit of code reads 8 bytes array , converts int64.

i know how tweak code work when receiving data represented 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 help!

how about:

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

and cleaned into:

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

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -