Skip to content

Octal to Binary Convert #8949

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

Merged
merged 25 commits into from
Aug 20, 2023
Merged
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c115900
Octal to Binary Convert
Aug 11, 2023
8277f5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
6999155
mention return type
BamaCharanChhandogi Aug 11, 2023
7ad4dd0
code scratch
Aug 13, 2023
2d73603
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2023
b03c5a3
Merge branch 'TheAlgorithms:master' into OctalToBinary
BamaCharanChhandogi Aug 13, 2023
7b0ac71
mentioned return type
Aug 13, 2023
0f3e4bb
Merge branch 'OctalToBinary' of https://github.com/BamaCharanChhandog…
Aug 17, 2023
33f7f8e
Merge branch 'TheAlgorithms:master' into OctalToBinary
BamaCharanChhandogi Aug 17, 2023
8be37da
Merge branch 'OctalToBinary' of https://github.com/BamaCharanChhandog…
Aug 17, 2023
3040f99
remove comment
Aug 17, 2023
fa33d5c
added documention and some test cases
Aug 18, 2023
ee728ee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2023
275e12d
Merge branch 'TheAlgorithms:master' into OctalToBinary
BamaCharanChhandogi Aug 18, 2023
9e75dd7
add another test case
Aug 18, 2023
8906c9d
fixes documention
Aug 18, 2023
920fcc4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 18, 2023
80d79eb
Merge branch 'TheAlgorithms:master' into OctalToBinary
BamaCharanChhandogi Aug 19, 2023
d5eacd9
Documention and test cases added
BamaCharanChhandogi Aug 19, 2023
eb4d80e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2023
37e3391
documention problem solved
BamaCharanChhandogi Aug 19, 2023
25921bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2023
7e9f2af
error in exit 1
BamaCharanChhandogi Aug 20, 2023
761e1f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2023
2e91bcf
Apply suggestions from code review
tianyizheng02 Aug 20, 2023
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
29 changes: 29 additions & 0 deletions conversions/octal_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def octal_to_binary(octal_number):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: octal_to_binary. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: octal_number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check again

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: octal_to_binary. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file conversions/octal_to_binary.py, please provide doctest for the function octal_to_binary

Please provide type hint for the parameter: octal_number

"""
Convert an octal number to binary.

Args:
octal_number (str): The octal number as a string.

Returns:
str: The binary representation of the octal number.
"""
binary_number = ""
octal_digits = "01234567"

for digit in octal_number:
if digit not in octal_digits:
raise ValueError("Invalid octal digit")

binary_digit = ""
value = int(digit)
for _ in range(3):
binary_digit = str(value % 2) + binary_digit
value //= 2
binary_number += binary_digit

return binary_number

if __name__ == "__main__":
import doctest
doctest.testmod()