binaryCalculatorPrototype/BasicRegister.py

25 lines
891 B
Python
Raw Normal View History

2023-06-17 21:41:51 +03:00
class BasicRegister:
def __init__(self, memory: list[bool]):
self.memory: list[bool] = memory
def __str__(self) -> str:
return f"Memory: [{', '.join([str(int(value)) for value in self.memory])}]"
def reverse(self):
self.memory = [not value for value in self.memory]
2023-06-18 14:51:13 +03:00
def left_shift(self, digit_to_fill: bool = False, steps_shifted: int = 1) -> list[bool]:
self.memory.extend([digit_to_fill] * steps_shifted)
2023-06-17 21:41:51 +03:00
shifted_radices: list[bool] = self.memory[:steps_shifted]
del self.memory[:steps_shifted]
return shifted_radices
2023-06-18 14:51:13 +03:00
def right_shift(self, digit_to_fill: bool = False, steps_shifted: int = 1) -> list[bool]:
self.memory[:0] = [digit_to_fill] * steps_shifted
2023-06-17 21:41:51 +03:00
shifted_radices: list[bool] = self.memory[-steps_shifted:]
del self.memory[-steps_shifted:]
return shifted_radices