Jarod Cavalcante
2024-11-12T02:12:42Z

decimal_to_binary.py

| def decimal_to_binary_32bit(number):
| return format(number, '032b')
|
| addresses = [3, 180, 43, 2, 191, 88, 190, 14, 181, 44, 186, 253]
|
| results = []
|
| num_blocks = 16
| index_bits = 4
|
| def calculate_tag_index(address):
| binary_address = decimal_to_binary_32bit(address)
| index = binary_address[-index_bits:]
| tag = binary_address[:-index_bits]
| return binary_address, tag, index
|
| cache = [{"tag": None} for _ in range(num_blocks)]
|
| def check_cache(address, tag, index):
| index_value = int(index, 2)
| cache_block = cache[index_value]
| if cache_block["tag"] == tag:
| return "Acerto"
| else:
| cache[index_value]["tag"] = tag
| return "Falha"
|
| for address in addresses:
| binary_address, tag, index = calculate_tag_index(address)
| result = check_cache(address, tag, index)
| results.append((address, binary_address, tag, index, result))
|