Iceshrimp.NET/Iceshrimp.Backend/Core/Helpers/LongExtensions.cs
2023-12-24 00:57:07 +01:00

31 lines
No EOL
662 B
C#

using System.Text;
namespace Iceshrimp.Backend.Core.Helpers;
public static class NumberExtensions {
private const string Base36Charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static string ToBase36(this long input) {
if (input == 0) return "0";
var result = new StringBuilder();
while (input > 0) {
result.Append(Base36Charset[(int)(input % 36)]);
input /= 36;
}
return result.ToString();
}
public static string ToBase36(this int input) {
if (input == 0) return "0";
var result = new StringBuilder();
while (input >= 0) {
result.Append(Base36Charset[input % 36]);
input /= 36;
}
return result.ToString();
}
}