Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert decimal to Variable Byte code & gamma code

How do you convert the decimal number 777 to the equivalent VB & gamma codes?

I've been reading up on gamma codes. I see where they get the unary codes from the decimal but not where the length & offset comes from. I also understand that the gamma code is just the length (of the unary code) concatenated with the offset.

like image 618
Adam Lynch Avatar asked Dec 13 '11 15:12

Adam Lynch


2 Answers

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.


like image 149
Ben.K Avatar answered Dec 18 '22 08:12

Ben.K


777 in binary code: 1100001001

  • VB code: 00000110 10001001 (start to fill 7 bytes if you did not finish put 1 on the 8th bit else 0)
  • gamma code: 1111111110100001001
  • offset: 100001001
  • length: 1111111110
like image 33
Oana Avatar answered Dec 18 '22 09:12

Oana