The reason ZigZag encoding evolved as it did is because it can be applied as
a separate layer on top of varint encoding.  Originally, ZigZag was not
officially part of the protobuf spec, but just something some people did
manually to encode negative numbers efficiently.  Eventually we made it
official.  Your encoding would work equally well, but cannot really be
implemented independently of varint itself, therefore could not have evolved
into existence in this way.

On Fri, Jan 14, 2011 at 12:07 AM, David Srbecky <dsrbe...@gmail.com> wrote:

> 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.
>
> --
> 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
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
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 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to