fix BasicRegister shrinking

This commit is contained in:
dymik739 2023-06-26 22:33:41 +03:00
parent 8f68099309
commit f2ee4cd709
2 changed files with 3 additions and 3 deletions

View File

@ -27,7 +27,7 @@ class BasicRegister:
"""
current_memory_size: int = len(self.memory)
return BasicRegister(
[False] * max(resulting_size - current_memory_size, 0) + list(self.memory)[-current_memory_size:]
[False] * max(resulting_size - current_memory_size, 0) + list(self.memory)[-resulting_size:]
)
def reverse(self):
@ -87,7 +87,7 @@ def binary_sum(a_original: BasicRegister, b_original: BasicRegister) -> BasicReg
c = BasicRegister([False] * required_size)
carry = False
for i in range(size_a - 1, 0, -1):
for i in range(required_size - 1, 0, -1):
current_bit_sum = a.memory[i] + b.memory[i] + carry
carry = bool(current_bit_sum & 2)
c.memory[i] = bool(current_bit_sum & 1)

View File

@ -23,6 +23,6 @@ if __name__ == '__main__':
reg2: BasicRegister = BasicRegister(get_memory("more memory"))
reg3: BasicRegister = sum(reg, reg2)
reg3: BasicRegister = binary_sum(reg, reg2)
print(reg3)