Compare commits

..

2 Commits

2 changed files with 11 additions and 4 deletions

View File

@ -4,7 +4,7 @@ from collections import deque
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.
:param deque[bool] memory: The bits stored inside the register.
"""
def __init__(self, memory: list[bool]):
@ -15,7 +15,8 @@ class BasicRegister:
return f"Memory: {[int(value) for value in self.memory]}"
def reverse(self):
self.memory = [not value for value in self.memory]
for i, value in enumerate(self.memory):
self.memory[i] = not value
def left_shift(self, digit_to_fill: bool = False, steps_shifted: int = 1) -> deque[bool]:
self.memory.extend([digit_to_fill] * steps_shifted)

10
main.py
View File

@ -1,16 +1,22 @@
from bitutilities import *
import timeit
if __name__ == '__main__':
reg: BasicRegister = BasicRegister(get_memory("memory"))
# print(type(reg))
print("\nRegister:")
print(reg)
print()
print("\nReversed:")
reg.reverse()
print(reg)
print("\nShifted left:")
print([int(value) for value in reg.left_shift()])
print(reg)
print()
print("\nShifted right:")
print([int(value) for value in reg.right_shift()])
print(reg)