Skip to content

using only loop, param expansion and printf to convert string to integer #53

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 1 commit into from
Jun 19, 2025

Conversation

ephiguxta
Copy link
Contributor

Hello, it's been a while :)

This PR proposes using only printf to convert string to integer.
For example, if we try to convert chars that the ASCII Table doesn't include, we'll get a negative number:

$ bh_str2dec "olá mundo"
111 108 -61 -95 32 109 117 110 100 111

But, with printf we get the positive value beyond the scope of ASCII:

$ bh_str2dec "olá mundo"
111 108 225 109 117 110 100 111

@merces
Copy link
Owner

merces commented Jun 19, 2025

Beautiful. Thanks!

@merces merces merged commit d8eec03 into merces:master Jun 19, 2025
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.

2 participants