Java Utililty Methods Zigzag Encode

List of utility methods to do Zigzag Encode

Description

The list of methods to do Zigzag Encode are organized into topic(s).

Method

byte[]zigzagEncode(byte[] data)
zigzag Encode
byte[] result = new byte[64];
for (int i = 0; i < naturalOrder.length; i++) {
    result[i] = data[naturalOrder[i]];
return result;
intzigZagEncode(int i)
Same as #zigZagEncode(long) but on integers.
return (i >> 31) ^ (i << 1);
intzigzagEncode(int input)
zigzag Encode
return (input << 1) ^ (input >> 31);
intzigzagEncode(int input)
zigzag Encode
if (input < 0) {
    return (input << 1) ^ -1;
return (input << 1);
longzigZagEncode(long l)
Zig-zag encode the provided long.
return (l >> 63) ^ (l << 1);
longzigZagEncode(long n)
Zig-zag encode: this helps transforming small signed numbers into small positive numbers.
return (n >> 63) ^ (n << 1);
longzigzagEncode(long val)
zigzag encode the given value
return (val << 1) ^ (val >> 63);
int[]zigZagSort(int[] array)
Sort an array in zig-zag pattern i.e.
for (int i = 1; i < array.length; i++) {
    if ((i % 2 == 1 && array[i] < array[i - 1]) || (i % 2 == 0 && array[i] > array[i - 1])) {
        int temp = array[i];
        array[i] = array[i - 1];
        array[i - 1] = temp;
return array;
...
intzigzagToInt(final int n)
zigzag To Int
return (n >>> 1) ^ -(n & 1);