Java Zigzag Encode zigZagEncode(int i)

Here you can find the source of zigZagEncode(int i)

Description

Same as #zigZagEncode(long) but on integers.

License

Apache License

Declaration

private static final int zigZagEncode(int i) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /** Same as {@link #zigZagEncode(long)} but on integers. */
    private static final int zigZagEncode(int i) {
        return (i >> 31) ^ (i << 1);
    }// ww w .  ja  v a2s .  com

    /**
     * <a href="https://developers.google.com/protocol-buffers/docs/encoding#types">Zig-zag</a>
     * encode the provided long. Assuming the input is a signed long whose
     * absolute value can be stored on <tt>n</tt> bits, the returned value will
     * be an unsigned long that can be stored on <tt>n+1</tt> bits.
     */
    private static final long zigZagEncode(long l) {
        return (l >> 63) ^ (l << 1);
    }
}

Related

  1. zigzagEncode(byte[] data)
  2. zigzagEncode(int input)
  3. zigzagEncode(int input)
  4. zigZagEncode(long l)
  5. zigZagEncode(long n)