Compare commits
2 Commits
66c9f833a6
...
f747e3b530
Author | SHA1 | Date |
---|---|---|
Rhinemann | f747e3b530 | |
Rhinemann | f508ca51c8 |
|
@ -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
10
main.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue