-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Allow int.ToString and Parse to support radixes other than base-10 and base-16 #50491
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I've updated the issue title to be a bit more descriptive. Can you describe your scenario a bit more? We already have inbox support for base10 and base16. Is base2 (binary) the most interesting radix for your workloads? The main ECMAScript has a radix parameter is that historically, its parse routine tries to deduce the representation of the incoming number, but this can lead to incorrect guesses. For example, .NET doesn't have this same behavior, since all numbers are emitted and parsed as decimal by default. There's no auto-detection of octal vs. hex vs. decimal in the parsing routines. So there has historically been no need to have a specialized radix parameter. |
Sometimes I need use following radixes.
|
Just FYI, the Convert class already supports the ToString aspect of this for base 2, 8, 10, and 16, e.g. Convert.ToString(12345, 2) produces
|
Closing in favor of #83619 While this API would be "more extensible" overall, it doesn't fit the current conventions and would be more work for less obvious overall benefits.
|
Background and Motivation
In ECMAScript (JS) world, we can parse an integer with a radix to specify its positional notation like following.
And we can also stringify a number (convert a number to string) with a radix (positional notation) like following.
Currently now .NET only supports DEC and HEX but JS supports 2-36.
Proposed API
Implementation
Following are some sample codes of the implementation to convert a number to a string with a specific radix.
int.ToString
long.ToString
double.ToString
Following are about parsing.
int.Parse
long.Parse
int.TryParse
long.TryParse
Usage Examples
The text was updated successfully, but these errors were encountered: