Java Zigzag Decode zigzagDecode(int encoded)

Here you can find the source of zigzagDecode(int encoded)

Description

zigzag Decode

License

Open Source License

Declaration

public static int zigzagDecode(int encoded) 

Method Source Code

//package com.java2s;

public class Main {
    public static int zigzagDecode(int encoded) {
        // canonical:
        //return (encoded >>> 1) ^ (-(encoded & 1));
        if ((encoded & 1) == 0) { // positive
            return (encoded >>> 1);
        }//w  w  w .j  a v  a 2s.  c  o  m
        // negative
        return (encoded >>> 1) ^ -1;
    }

    public static long zigzagDecode(long encoded) {
        // canonical:
        //return (encoded >>> 1) ^ (-(encoded & 1));
        if ((encoded & 1) == 0) { // positive
            return (encoded >>> 1);
        }
        // negative
        return (encoded >>> 1) ^ -1L;
    }
}

Related

  1. zigzagDecode(int encoded)
  2. zigZagDecode(int i)
  3. zigzagDecode(int[] src)
  4. zigZagDecode(long n)
  5. zigzagDecode(long val)