Background and motivation
I'm working on some code that contains fields that represent numbers in octal base, saved as ASCII characters.
To convert them to a ten base number, I need to do the following:
byte[]buffer=new[]{0x30,0x30,0x30,0x30,0x36,0x34,0x34,0x0};// 0000644\0stringstr=Encoding.ASCII.GetString(buffer.AsSpan());// "000644"inttenBaseNumber=Convert.ToInt32(str,fromBase:8);// 420The third line is inefficient. Ideally, I should be able to pass a the string as a ReadOnlySpan<char>.
This can be a problem in my use case, because when I open a tar archive, I need to iterate through all the tar entries, and each entry header has multiple octal fields like the one above.
API Proposal
namespaceSystem{publicstaticclassConvert{publicstaticintToInt32(ReadOnlySpan<char>value,intfromBase);}}API Usage
inttenBaseNumber=Convert.ToInt32(str.AsSpan(),fromBase:8);// 420
If this gets approved, I can work on adding this API.
cc @GrabYourPitchforks
Background and motivation
I'm working on some code that contains fields that represent numbers in octal base, saved as ASCII characters.
To convert them to a ten base number, I need to do the following:
The third line is inefficient. Ideally, I should be able to pass a the
stringas aReadOnlySpan<char>.This can be a problem in my use case, because when I open a tar archive, I need to iterate through all the tar entries, and each entry header has multiple octal fields like the one above.
API Proposal
API Usage
If this gets approved, I can work on adding this API.
cc @GrabYourPitchforks