2
In a college job we were required to simulate the functioning of a RAM memory. The user can read or write in the cells of this memory or all Zera, and each one stores 8 bits. That part’s already done, but there’s something I can’t fix. The user can ask for the address of a cell or read its contents in binary or hexadecimal according to his choice, but I’m having difficulty converting the elements of each cell (which are already in binary) to hexadecimal.
The code is like this:
import numpy as np
celulas = np.array([(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0)])
while True:
operação = str(input('Ler[A], Escrever[B] ou Limpar[c]? Para terminar a aplicação[D]')).upper()
if operação == 'A':
endereço = int(input('Qual célula ler?'))
base = int((input('Você quer ler em binário(1) ou em hexadecimal(2)?')))
if base == 1:
cels = [str(i) for i in celulas[endereço - 1]]
print(''.join(cels))
if operação == 'B':
endereço = int(input('Qual célula escrever?'))
cont = 0
while cont <= 7:
celulas[endereço-1][cont] = int(input('Digite 1 ou 0'))
cont += 1
if operação == 'C':
cont = 0
while cont <= 31:
celulas[cont] = (0,0,0,0,0,0,0,0)
cont += 1
if operação == 'D':
break
From now on, thank you.
Perfect, my friend, it worked. Thank you very much
– Lucas Nobre