class hexxi(): def __init__(self,hexxi,bin_flag=False): #Use the bin_flag to convert bin to hex #durring object initation self.nibbles = { #binary to hex conversion chart ( wanted search, should'ah used base numbers ): ) "0":"0000", "1":"0001", "2":"0010", "3":"0011", "4":"0100", "5":"0101", "6":"0110", "7":"0111", "8":"1000", "9":"1001", "a":"1010", "b":"1011", "c":"1100", "d":"1101", "e":"1110", "f":"1111" } self.hexxi = hexxi h = "" if bin_flag: # reason to want search ... for x in range(0,len(hexxi)/4): h2 = hexxi[x*4:(x*4)+4] for k in self.nibbles: if self.nibbles[k] == h2: h += k self.hexxi = h def __str__(self): #access object as string and you'll get a binary string r = "" for i in self.hexxi: r += self.nibbles[i] return r def __getitem__(self,q): #access object as list and you'll get #a single row of binary, equal in length to the #square root of the lenth of the biary equivilent of your hex. #userful for bitmap/hex spriting (storing lil b/w images) l = len(self.hexxi)*4 r = 0 if l == 4*4: # 4x4 sprites r = [str(self.hexxi[i:i+1]) for i in range(0, len(self.hexxi), 1)] if l == 8*8: # 8x8 sprites r = [str(self.hexxi[i:i+2]) for i in range(0, len(self.hexxi), 2)] if l == 16*16: # 16x16 sprites r = [str(self.hexxi[i:i+4]) for i in range(0, len(self.hexxi), 4)] if l == 32*32:# 32x32 sprites r = [str(self.hexxi[i:i+8]) for i in range(0, len(self.hexxi), 8)] if l == 64*64:# 64x64 sprites r = [str(self.hexxi[i:i+16]) for i in range(0, len(self.hexxi), 16)] return r[q] #return sprite row as binary string