encodeZigZag64 function

int encodeZigZag64(
  1. int n
)

ZigZag-encodes a signed 64-bit integer.

Same principle as encodeZigZag32 but uses a 63-bit arithmetic shift to handle the full 64-bit signed range.

Formula: (n << 1) ^ (n >> 63)

Implementation

int encodeZigZag64(int n) {
  return (n << 1) ^ (n >> 63);
}