-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
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
Octal to Binary Convert #8949
Changes from 4 commits
c115900
8277f5b
6999155
7ad4dd0
2d73603
b03c5a3
7b0ac71
0f3e4bb
33f7f8e
8be37da
3040f99
fa33d5c
ee728ee
275e12d
9e75dd7
8906c9d
920fcc4
80d79eb
d5eacd9
eb4d80e
37e3391
25921bd
7e9f2af
761e1f7
2e91bcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
def octal_to_binary(octal_number): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter:
BamaCharanChhandogi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Convert an octal number to binary. | ||
|
||
tianyizheng02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Args: | ||
octal_number (str): The octal number as a string. | ||
|
||
Returns: | ||
str: The binary representation of the octal number. | ||
""" | ||
tianyizheng02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check again