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

tpGit-converter-Hadj-Taric #77

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e29d028
Adds function to "say hello"
rgt-yncrea Sep 19, 2022
001ab4a
Creates a decimal to binary converter
rgt-yncrea Sep 19, 2022
cd3b000
Adds a binary to decimal converter
rgt-yncrea Sep 19, 2022
96a3f84
Improves speed of conversion
rgt-yncrea Sep 19, 2022
ff5f0fa
Adds some documentation to converters
rgt-yncrea Sep 19, 2022
4c1e33d
Adds some input values check
rgt-yncrea Sep 19, 2022
c098a3b
Checks that only bits are passed to conv
rgt-yncrea Sep 19, 2022
2435632
Refactors bits verification
rgt-yncrea Sep 19, 2022
cb3af7e
Fixes bits check
rgt-yncrea Sep 19, 2022
7a6358a
Adds UT for converter
rgt-yncrea Sep 22, 2022
9d3866f
Fix converter bugs
rgt-yncrea Sep 22, 2022
fe7bcce
Merge pull request #1 from Taric-Hadj/decimal-binary-converter
Taric-Hadj Sep 29, 2022
a1d2dfa
Merge branch 'main' into dev
Taric-Hadj Sep 29, 2022
6814d15
Merge pull request #2 from Taric-Hadj/dev
Taric-Hadj Sep 29, 2022
34dc382
Create python-publish.yml
Taric-Hadj Sep 29, 2022
fc9e72c
commit
Taric-Hadj Sep 29, 2022
c7a72ff
commit
Taric-Hadj Sep 29, 2022
86cdf26
commit
Taric-Hadj Sep 29, 2022
f19e796
Update test_converter.py
Taric-Hadj Sep 29, 2022
335bd80
Update .DS_Store
Taric-Hadj Sep 29, 2022
08f3f99
commit
Taric-Hadj Sep 29, 2022
bb5e674
Merge branch 'main' of https://github.com/Taric-Hadj/M1-2022-git-work…
Taric-Hadj Sep 29, 2022
ca7bc69
commit
Taric-Hadj Sep 29, 2022
19050a9
Update python-publish.yml
Taric-Hadj Sep 29, 2022
84fa55e
Update python-publish.yml
Taric-Hadj Sep 29, 2022
bfffbc2
Update test_converter.py
Taric-Hadj Sep 29, 2022
2ceb472
commit
Taric-Hadj Sep 29, 2022
42a0255
Merge branch 'main' of https://github.com/Taric-Hadj/M1-2022-git-work…
Taric-Hadj Sep 29, 2022
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
Refactors bits verification
Check if inputs is made of bits only in a separate function
rgt-yncrea committed Sep 19, 2022
commit 24356324765c7c1f2feaa9c67f68a7a7066d9c35
12 changes: 9 additions & 3 deletions converter.py
Original file line number Diff line number Diff line change
@@ -20,9 +20,15 @@ def bin_to_dec(bits_array: List[int]) -> int:
:param bits_array: list of 0s and 1s to convert
:return: int
"""
for b in bits_array:
if b not in [0, 1]:
raise ValueError("input should contain only bits (0 or 1)")
if not inputs_is_bits(bits_array):
raise ValueError("input should contain only bits (0 or 1)")

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


def inputs_is_bits(bits_array):
for b in bits_array:
if b not in [0, 1]:
return False