777 in binary code is 1100001001
Gamma code
- calculate offset: remove the first 1 is 100001001
- calculate length: how many bit of offset(9 bits) in unary code 1111111110 (nine 1s and one 0)
- put them together 1111111110100001001
VB code
- Get the last seven bits from the binary code 1100001001 is 0001001, add 1 as the "head" bit (0001001 -> 10001001) because there are still 3 bits left in the original binary code.
- Get the remain 3 bits, this time use 0 as the "head" bit (110 -> 00000110) because there is no remainder in the original binary code
- put these two bytes together 0000011010001001 is the VB code.
In esence, VB code splits the gap (in binary) into 7 bit partitions and set the continuation bit/1st bit of last/right most 7 bits part to 1 and all other parts's continuation bit to 0.