126 is 0000 0000 0111 1110 in binary.  We truncate it form the left to
groups of seven: 0000000 1111110 and then encode it as usual (least
significant group first): 1 1111110  0 0000000.  It takes two bytes to
encode, but so does the zig-zag encoding.

In fact, the zig-zag encoding and the two's complement encoding always
take the same number of bytes to encode a given number.

Both of the encodings do not care what the original bitness of the
integer was.  Two's complement works the same way for 64-bit number,
32-bit number and 7-bit number (as used for the encoding).

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to