import binascii char = [ 0x7C, #/* 01 11 11 00*/ 0x40, #/* 01 00 00 00 */ 0x40, #/* 01 00 00 00 */ 0x78, #/* 01 11 10 00 */ 0x40, #/* 01 00 00 00 */ 0x40, #/* 01 00 00 00 */ 0x7C, #/* 01 11 11 00 */ 0x00, #/* 00 00 00 00 */ ] res = [ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00 ] bitmap = [ 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xF0, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ] def transpose(char): N = len(char) transposed = [] for i in range(N): newbyte = 0 for j, byte in enumerate(char): if (byte & (1 << N-i-1)): newbyte |= 1 << j transposed.append(newbyte) return transposed t = transpose(char) print(t) print(res) print([format(b, '02x') for b in t]) s = "[0x{0:02X}, 0x{1:02X}, 0x{1:02X}, 0x{1:02X}, 0x{1:02X}, 0x{1:02X}, 0x{1:02X}, 0x{1:02X}]".format(*t) print(s)