def ZigZagEncode(value):
 if (value >= 0):
  return (value << 1)
 return ((value << 1) ^ (~ 0))

def ZigZagEncode ( value ) : if ( value >= 0 ) : return ( value << 1 ) return ( ( value << 1 ) ^ ( ~ 0 ) )
zigzag transform: encodes signed integers so that they can be effectively used with varint encoding .