C
C#3mo ago
Frite

How do i quickly convert to base 9 ?

No description
12 Replies
Frite
FriteOP3mo ago
am i forced to create an entire base converter ?
canton7
canton73mo 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
FriteOP3mo ago
:catsweat:
joy
joy3mo ago
Yep, Convert.ToString only supports base 2, 8, 10, 16.
Frite
FriteOP3mo 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
Angius3mo ago
How do you, mathematically, convert between base 2 and base 10? Without using a loop
Frite
FriteOP3mo ago
i remember doing it at school but its only to base 10 you're right
canton7
canton73mo 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
Angius3mo ago
Could be, I'd have to benchmark it ig
Frite
FriteOP3mo ago
alright this is the result
Frite
FriteOP3mo ago
but because of performance issue my bot is very dumb
Want results from more Discord servers?
Add your server