Commit.
This commit is contained in:
parent
9118bb16a9
commit
198e984e32
|
@ -1,8 +1,29 @@
|
|||
def get_memory(variable_name: str) -> list[bool]:
|
||||
"""
|
||||
Reads user input to be used as a memory array.
|
||||
|
||||
:param str variable_name: The name to be displayed in the input line.
|
||||
|
||||
:return: A list of boolean values read from user.
|
||||
:rtype: list[bool]
|
||||
"""
|
||||
while True:
|
||||
input_chars: list[str] = list(input(f"Enter {variable_name}: "))
|
||||
|
||||
if all(character in ["0", "1"] for character in input_chars):
|
||||
return [True if character == "1" else False for character in input_chars]
|
||||
else:
|
||||
print(f"[ERROR] The {variable_name} may contain only 1-s and 0-s!")
|
||||
|
||||
|
||||
class BasicRegister:
|
||||
"""The BasicRegister represents a hardware register capable of manipulating multiple bits at a time.
|
||||
|
||||
:param list[bool] memory: The bits stored inside the register.
|
||||
"""
|
||||
|
||||
def __init__(self, memory: list[bool]):
|
||||
"""Constructor method"""
|
||||
self.memory: list[bool] = memory
|
||||
|
||||
def __str__(self) -> str:
|
12
main.py
12
main.py
|
@ -1,14 +1,4 @@
|
|||
from BasicRegister import BasicRegister
|
||||
|
||||
|
||||
def get_memory(variable_name: str) -> list[bool]:
|
||||
while True:
|
||||
input_chars: list[str] = list(input(f"Enter {variable_name}: "))
|
||||
|
||||
if all(character in ["0", "1"] for character in input_chars):
|
||||
return [True if character == "1" else False for character in input_chars]
|
||||
else:
|
||||
print(f"[ERROR] The {variable_name} may contain only 1-s and 0-s!")
|
||||
from bitutilities import *
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue