5

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.

Community
  • 1
  • 1
Adam Lynch
  • 3,341
  • 5
  • 36
  • 66
  • Well like I said I've gotten from decimal to unary. And length & offset to gamma. But for the life of me I can't seem to see the connection. And I cannot find anything on VB codes anywhere online and nothing but that link on gamma codes. Nothing whatsoever in my notes – Adam Lynch Dec 13 '11 at 16:18

2 Answers2

8

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.


Laksitha Ranasingha
  • 4,321
  • 1
  • 28
  • 33
Ben.K
  • 93
  • 1
  • 4
  • 3
    'calculate length: how many bit of offset(9 bits) in unary code 1111111110 (nine 1s and one 0)' --> Can you explain this a little more? I'm lost at this point – Thang Do Jun 16 '16 at 13:21
1

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
Community
  • 1
  • 1
Oana
  • 19
  • 1