Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOISSON_Louise_Converter #99

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix converter bugs
rgt-yncrea committed Sep 22, 2022
commit 9d3866f60cea1bf58fb743cdcbd2701020f99a27
4 changes: 2 additions & 2 deletions converter.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ def dec_to_bin(n: int) -> List[int]:
raise ValueError("n should be positive")

bit = [0 if n % 2 == 0 else 1]
return bit if n <= 1 else dec_to_bin(n >> 2) + bit
return bit if n <= 1 else dec_to_bin(n >> 1) + bit


def bin_to_dec(bits_array: List[int]) -> int:
@@ -25,7 +25,7 @@ def bin_to_dec(bits_array: List[int]) -> int:

ba = bits_array.copy()
ba.reverse()
return sum([1 << i * m for i, m in enumerate(ba)])
return sum([(1 << i) * m for i, m in enumerate(ba)])


def inputs_is_bits(bits_array):