Converter.ZigZagEncode Method
Namespace: Riptide.Utils
Assembly: RiptideNetworking.dll
Overloads
ZigZagEncode(int) | Zig zag encodes |
ZigZagEncode(long) | Zig zag encodes |
ZigZagEncode(int)
Zig zag encodes value
.
public static int ZigZagEncode(int value)
Parameters
int | value |
The value to encode. |
Returns
int | The zig zag-encoded value. |
Remarks
Zig zag encoding allows small negative numbers to be represented as small positive numbers. All positive numbers are doubled and become even numbers, while all negative numbers become positive odd numbers. In contrast, simply casting a negative value to its unsigned counterpart would result in a large positive number which uses the high bit, rendering compression via AddVarULong(ulong) and GetVarULong() ineffective.
ZigZagEncode(long)
Zig zag encodes value
.
public static long ZigZagEncode(long value)
Parameters
long | value |
The value to encode. |
Returns
long | The zig zag-encoded value. |
Remarks
Zig zag encoding allows small negative numbers to be represented as small positive numbers. All positive numbers are doubled and become even numbers, while all negative numbers become positive odd numbers. In contrast, simply casting a negative value to its unsigned counterpart would result in a large positive number which uses the high bit, rendering compression via AddVarULong(ulong) and GetVarULong() ineffective.