Re: bar code bit encoding

From: Jan Karrman <jan_at_it_dot_uu_dot_se>
Date: Tue Sep 16 2003 - 07:45:40 CDT

On Tue, 16 Sep 2003, David Mertz wrote:

> Jan Karrman <> wrote:
> |I don't understand why we should store data in bytes or nibbles.
> |Why not store each individual bit as an element in a vector?
> See my example recently. If we align on nibbles--or really on digits
> for Code128--then during debugging we can recognize quickly, for
> example, that digit #17-19 encode the vote in contest #6. It's a lot
> quicker and more direct to figure out if and why those digits aren't
> getting the right values.
> Programmers find it really easy to read decimal digits, but not so easy
> to read bits (especially when those bits have an indirect relationship
> to the encoded digits).

I don't believe it is a good idea to encode the choices in the
decimal digits that are to be printed using the barcode, for the
simple reason that the string tends to become too long. Whatever
can go wrong, it certainly shouldn't be the conversion between
binary and decimal. I don't know if there is any builtin support
for this, otherwise it is very simple since Python has unlimited
precision integers:

def todecimal(bin):
    dec = 0
    pow = 1
    for i in bin:
        dec += i*pow
        pow *= 2
    return dec

def tobinary(dec):
    bin = []
    while dec > 0:
        bit = int(dec % 2)
        dec = (dec - bit)/2
    return bin

decimal = todecimal([1,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,0,0,0,0,1,0,0,1,1,1,0,1,0,1,1,1,1,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,1,1,1,1])
print decimal
print tobinary(decimal)

Note that when converting from decimal to binary to get back the
original bit vector from the decimal number, one may have to add
a number of zeroes (most significant zeroes will disappear).

To inspect a particular contest for debugging purposes one simply
extracts the proper slice of the bit vector. Okay, it's binary
digits, but if documented properly how the bits in each contest
are assigned, I don't think that should be a problem.

= The content of this message, with the exception of any external
= quotations under fair use, are released to the Public Domain
Received on Tue Sep 30 23:17:06 2003

This archive was generated by hypermail 2.1.8 : Tue Sep 30 2003 - 23:17:09 CDT