My data structure is initialized as follows:
[[0,0,0,0,0,0,0,0] for x in range(8)]
8 characters, 8 rows, each row has 5 bits for columns, so each integer can be in the range between 0 and 31 inclusive.
I have to convert the number 177 (can be between 0 and 319) into char, row, and column.
Let me try again, this time with a better code example. No bits are set.
Ok, I added the reverse to the problem. Maybe that'll help.
chars = [[0,0,0,0,0,0,0,0] for x in range(8)]
# reverse solution
for char in range(8):
for row in range(8):
for col in range(5):
n = char * 40 + (row * 5 + col)
chars[char][row] = chars[char][row] ^ [0, 1<<4-col][row < col]
for data in range(320):
char = data / 40
col = (data - char * 40) % 5
row = ?
print "Char %g, Row %g, Col %g" % (char, row, col), chars[char][row] & 1<<4-col