byteReverse

byteReverse(integer x) → integer reversed

Returns the number obtained by reversing the order of the 8 bytes of the 64-bit integer x: the least significant byte becomes the most significant byte, and so on. The bits inside each byte do not move. The original number is not modified.

This is the byte-order (endianness) swap. The reversal always covers all 8 bytes, including the leading zero bytes: byteReverse(1) returns 72057594037927936, that is, 1 followed by 56 zeros in binary.

byteReverse(0)       // 0
byteReverse(1)       // 72057594037927936: byte 01 moves to the very top
hexString(byteReverse(0x0102))  // "201000000000000": 01 02 becomes 02 01 00 00 00 00 00 00
byteReverse(byteReverse(0x0102))  // 258, that is, 0x0102
Math.byteReverse(0)  // 0
Math.byteReverse(1)  // 72057594037927936: byte 01 moves to the very top
Math.byteReverse(0x0102).toString(16)  // "201000000000000"
Math.byteReverse(0)  # 0
Math.byteReverse(1)  # 72057594037927936: byte 01 moves to the very top
hex(Math.byteReverse(0x0102))  # '0x201000000000000'
Parameters
Return
Note