fromZigzag

Reverts a given zigzag-encoded ((n << 1) ^ (n >> (T.sizeof * 8 - 1))) unsigned value to signed.

T
fromZigzag
(
T
)
(
T n
)

Examples

Varint examples.

1 ubyte[] b1 = [0b0000_0001];
2 assert(fromVarint!int(b1) == 1);
3 
4 ubyte[] b128 = [0b1000_0000, 0b0000_0001];
5 assert(fromVarint!int(b128) == 128);
6 
7 ubyte[] b300 = [0b1010_1100, 0b0000_0010];
8 assert(fromVarint!int(b300) == 300);
9 
10 ubyte[] bneg1 = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01];
11 assert(-1 == fromVarint!int(bneg1));
12 
13 ubyte[] bneg1_sint = [0x01];
14 assert(-1 == fromVarint!int(bneg1_sint).fromZigzag);
15 
16 ubyte[] b1_sint = [0x02];
17 assert(1 == fromVarint!int(b1_sint).fromZigzag);

Meta