addresses_part_a = [3,180,43,2,191,88,190,14,181,44,186,253] addresses_part_b = [21,166,201,143,61,166,62,133,111,143,144,61] addresses = addresses_part_a for addr in addresses: block = addr % 16 # block is the lower order four bits tag = addr >> 4 # tag is the rest of the address # convert the address to binary and drop the # leading '0b' and pad with leading zeros # to make it 8 bits long addr_in_binary = bin(addr)[2:] addr_in_binary = '0'*(8 - len(addr_in_binary)) + addr_in_binary # do the same thing to the tag, but only # pad to make it four bits tag_in_binary = bin(tag)[2:] tag_in_binary = '0'*(4 - len(tag_in_binary)) + tag_in_binary # print the table with some tabs to make it line up print addr, '\t', addr_in_binary, '\t', tag_in_binary, '\t', block