algorithm - Shortest Bit Sequence Logic -
i trying understand how shortest bit sequence work. mean logic. need create program don't know shortest bit sequence. tried google in vain. came across question on cant understand it. can explain me or guide me somewhere can understand logic behind this?
as jan dvorak pointed out in comments, it's number written in base -2
.
consider example [0, 1, 1, 1, 1, 1, 1]
.
the exponents of -2
same 2, with alternating signs:
(-2)^0 = 1 (-2)^1 = -2 (-2)^2 = 4 (-2)^3 = -8 (-2)^4 = 16 (-2)^5 = -32 (-2)^6 = 64 ...
in bit sequence notation lowest exponents come first, order reversed compared ordinary binary numbers.
[0, 1, 1, 1, 1, 1, 1] = 0 * (-2)^0 + 1 * (-2)^1 + 1 * (-2)^2 + 1 * (-2)^3 + 1 * (-2)^4 + 1 * (-2)^5 + 1 * (-2)^6
which gives (from bottom up)
[0, 1, 1, 1, 1, 1, 1] = 64 - 32 + 16 - 8 + 4 - 2 = 42
Comments
Post a Comment