Skip to content

Refactor binary to decimal conversion function#14571

Open
Ewanjohndennis wants to merge 2 commits intoTheAlgorithms:masterfrom
Ewanjohndennis:patch-3
Open

Refactor binary to decimal conversion function#14571
Ewanjohndennis wants to merge 2 commits intoTheAlgorithms:masterfrom
Ewanjohndennis:patch-3

Conversation

@Ewanjohndennis
Copy link
Copy Markdown

Rewrote bin_to_decimal to use Python's built-in int(s, 2) instead of a manual loop that accumulates the decimal value digit by digit. The logic and doctests are unchanged. Also added a guard for "-" as input, which previously slipped past the empty-string check and raised an unhelpful ValueError about non-binary values.

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

Rewrote bin_to_decimal to use Python's built-in int(s, 2) instead of a manual loop that accumulates the decimal value digit by digit. The logic and doctests are unchanged. Also added a guard for "-" as input, which previously slipped past the empty-string check and raised an unhelpful ValueError about non-binary values.
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Apr 21, 2026
@Ewanjohndennis
Copy link
Copy Markdown
Author

Ewanjohndennis commented Apr 22, 2026

Hi, thanks for the review!

Sorry for the ping, but since this PR has been approved, could a maintainer please take a look and merge if everything looks good?

@cclauss @MaximSmolskiy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants