Skip to content

Fix conversion from bases bigger than 36. - #63

Merged
Nickster258 merged 5 commits into
OpenRedstoneEngineers:mainfrom
JoBeGaming:fix-conversion-from-base-bigger-than-36
Aug 15, 2026
Merged

Fix conversion from bases bigger than 36.#63
Nickster258 merged 5 commits into
OpenRedstoneEngineers:mainfrom
JoBeGaming:fix-conversion-from-base-bigger-than-36

Conversation

@JoBeGaming

Copy link
Copy Markdown
Contributor

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.

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)

# ,642d 19bWBI
print(baseconvert("19bWBI", 64, 10))
# ,d264 1234567890
print(baseconvert("1234567890", 10, 64))
# ,642d 1Qnz
print(baseconvert("1Qnz", 64, 10))
# ,d264 371837
print(baseconvert("371837", 10, 64))
# ,642d abcdefg
print(baseconvert("abcdefg", 64, 10))
# ,d264 2514277534314
print(baseconvert("2514277534314", 10, 64))
# ,642d Hello
print(baseconvert("Hello", 64, 10))
# ,d264 295894002
print(baseconvert("295894002", 10, 64))

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.
Comment thread util.py
@JoBeGaming

Copy link
Copy Markdown
Contributor Author

Oops forgot the underscore part mentioned in https://discord.com/channels/116914772766752769/1350873703872725154/1537700822098378802. I'll add that rq.

@JoBeGaming

JoBeGaming commented Aug 14, 2026

Copy link
Copy Markdown
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 FateUnix29 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should totally merge this (LGTM).

@Nickster258 Nickster258 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty much just line spacing adjustments util.py.

Comment thread util.py
Comment thread util.py
@JoBeGaming
JoBeGaming requested a review from Nickster258 August 15, 2026 22:50
@Nickster258
Nickster258 merged commit c37bd0e into OpenRedstoneEngineers:main Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants