Fix conversion from bases bigger than 36. - #63
Merged
Nickster258 merged 5 commits intoAug 15, 2026
Merged
Conversation
The builtin `int` class can only convert from bases >= 2 and <= 36 (or 0), so we need our own handling for bigger bases. I guess the reason for the limit being at 36 is due to ambiguity with upper and lowercase letters.
FateUnix29
reviewed
Aug 14, 2026
Contributor
Author
|
Oops forgot the underscore part mentioned in https://discord.com/channels/116914772766752769/1350873703872725154/1537700822098378802. I'll add that rq. |
Contributor
Author
|
Also so Nick can be happy, I updated my tests (local), all still passing: # ,642d 1Qnz
assert baseconvert("1Qnz", 64, 10) == "371837"
# ,d264 371837
assert baseconvert("371837", 10, 64) == "1Qnz"
# ,642d abcdefg
assert baseconvert("abcdefg", 64, 10) == "2514277534314"
# ,d264 2514277534314
assert baseconvert("2514277534314", 10, 64) == "abcdefg"
# ,642d Hello
assert baseconvert("Hello", 64, 10) == "295894002"
# ,d264 295894002
assert baseconvert("295894002", 10, 64) == "Hello"
# ,642d 1Q_nz
assert baseconvert("1Q_nz", 64, 10) == "371837"
# ,d264 371_8_37
assert baseconvert("371_8_37", 10, 64) == "1Qnz"
# ,642d a_b_c_d_e_f_g
assert baseconvert("a_b_c_d_e_f_g", 64, 10) == "2514277534314"
# ,d264 251427753_4314
assert baseconvert("251427753_4314", 10, 64) == "abcdefg"
# ,642d Hel_lo
assert baseconvert("Hel_lo", 64, 10) == "295894002"
# ,d264 2958_9_4002
assert baseconvert("2958_9_4002", 10, 64) == "Hello"
# INVALID
try:
# ,642d _1Qnz
baseconvert("_1Qnz", 64, 10)
except BaseConversionError as err:
print(err)
try:
# ,d264 371837_
baseconvert("371837_", 10, 64)
except BaseConversionError as err:
print(err)
try:
# ,642d abc__defg
baseconvert("abc__defg", 64, 10)
except BaseConversionError as err:
print(err) |
FateUnix29
approved these changes
Aug 14, 2026
FateUnix29
left a comment
Contributor
There was a problem hiding this comment.
We should totally merge this (LGTM).
Nickster258
requested changes
Aug 15, 2026
Nickster258
left a comment
Member
There was a problem hiding this comment.
Pretty much just line spacing adjustments util.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The builtin
intclass can only convert from bases >= 2 and <= 36 (or 0), so we need our own handling for bigger bases. I guess the reason for the limit being at 36 is due to ambiguity with upper and lowercase letters.See https://discord.com/channels/116914772766752769/165640273810948097/1537648890847830089 for an example that didn't work, but now should work. I've tested this locally with following code (so Nick doesn't merge a bug)