C
C#2mo ago
Frite

How do i quickly convert to base 9 ?

No description
12 Replies
Frite
Frite2mo ago
am i forced to create an entire base converter ?
canton7
canton72mo ago
Yeah looks like that only supports some specific bases. Take a look at https://stackoverflow.com/questions/923771/quickest-way-to-convert-a-base-10-number-to-any-base-in-net
Stack Overflow
Quickest way to convert a base 10 number to any base in .NET?
I have and old(ish) C# method I wrote that takes a number and converts it to any base: string ConvertToBase(int number, char[] baseChars); It's not all that super speedy and neat. Is there a good,
Frite
Frite2mo ago
:catsweat:
hour
hour2mo ago
Yep, Convert.ToString only supports base 2, 8, 10, 16.
Frite
Frite2mo ago
i'm not sure about this one, it uses while loop. i need a lot of performance so i would use the mathematic method
Angius
Angius2mo ago
How do you, mathematically, convert between base 2 and base 10? Without using a loop
Frite
Frite2mo ago
i remember doing it at school but its only to base 10 you're right
canton7
canton72mo ago
I think using a List instead of a StringBuilder would be more efficient there:
var result = new List<char>();
// ...
result.Add(...);
// ...
return string.Concat(result.AsEnumerable().Reverse());
var result = new List<char>();
// ...
result.Add(...);
// ...
return string.Concat(result.AsEnumerable().Reverse());
That avoids having to constantly shuffle stuff around in the StringBuilder to make more room at the front
Angius
Angius2mo ago
Could be, I'd have to benchmark it ig
Frite
Frite2mo ago
alright this is the result
Frite
Frite2mo ago
but because of performance issue my bot is very dumb
Want results from more Discord servers?
Add your server