25 lines
809 B
Python
25 lines
809 B
Python
|
|
||
|
|
||
|
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]
|
||
|
|
||
|
def left_shift(self, steps_shifted: int) -> list[bool]:
|
||
|
self.memory.extend([False] * steps_shifted)
|
||
|
shifted_radices: list[bool] = self.memory[:steps_shifted]
|
||
|
del self.memory[:steps_shifted]
|
||
|
return shifted_radices
|
||
|
|
||
|
def right_shift(self, steps_shifted: int) -> list[bool]:
|
||
|
self.memory[:0] = [False] * steps_shifted
|
||
|
shifted_radices: list[bool] = self.memory[-steps_shifted:]
|
||
|
del self.memory[-steps_shifted:]
|
||
|
return shifted_radices
|