I was reading this document: http://www.fadden.com/techmisc/hdc/lesson11.htm
In it he stated:
Problem is, we don’t know how long
these are. So, we encode the length
with the unary coding we looked at
first (colons added for clarity):value binary coding 1 1: 2 01:0 3 01:1 4 001:00 5 001:01 16 00001:0000 64 0000001:000000 256 000000001:00000000This method is actually floor(log i)
zeros, followed by a 1, followed by
the binary code without the leading 1.
Since the first part is a unary count,
there is one ‘0’ for every bit in the
second part. This means we can
intersperse the data bits with the
zeros, like this:value binary coding 1 1 2 001 3 011 4 00001 5 00011 16 000000001 64 0000000000001 256 00000000000000001This has the same length, but can be
implemented with a simple shift
routine (assembly: shift left, if
carry set then exit, else shift the
next bit into the integer we’re
forming).
What exactly is this assembly shift and is it reversible, meaning can 00000000000000001 go back to 00000000100000000 without extra data?
An animation of an assembly shift would be excellent. Thanks
It’s a bit shift operation, see for instance this Wikipedia article: http://en.wikipedia.org/wiki/Bit_shift#Bit_shifts
The bits that get shifted out are usually not recoverable (except for rotate), so the operation is not reversible in itself. There are variants where, if you shift over just a single bit position, the value of the bit shifted out is saved in a flag register (the carry bit mentioned in your quote) where you can use it for a conditional jump.