Skip to content
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

Add optional second base argument to int DSL function #1244

Merged
merged 4 commits into from
Mar 24, 2023

Conversation

johnkerl
Copy link
Owner

@johnkerl johnkerl commented Mar 24, 2023

For issue #1241

int  (class=conversion #args=1,2) Convert int/float/bool/string to int. If the second argument is
omitted and the first argument is a string, base is inferred from the first argument's prefix. If
the second argument is provided and the first argument is a string, the second argument is used as
the base. If the second argument is provided and the first argument is not a string, the second
argument is ignored.

Examples:
int("345") gives decimal 345 (base-10/decimal input is inferred)
int("0xff") gives decimal 255 (base-16/hexadecimal input is inferred)
int("0377") gives decimal 255 (base-8/octal input is inferred)
int("0b11010011") gives decimal 211 which is hexadecimal 0xd3 (base-2/binary input is inferred)
int("0377", 10) gives decimal 377
int(345, 16) gives decimal 345
int(string(345), 16) gives decimal 837

@johnkerl johnkerl marked this pull request as ready for review March 24, 2023 03:56
@johnkerl johnkerl force-pushed the kerl/int-with-base branch 3 times, most recently from 1158ee2 to 345c661 Compare March 24, 2023 04:20
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.

1 participant