// using UnityEngine; public static class Base32 { private const string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; public static string ToString(uint number) { uint quotient = number / 32; uint remainder = number % 32; string res = CHARS[(int)remainder].ToString(); // Debug.Log(res); // Debug.Log("Q " + quotient); // Debug.Log("R " + remainder + " > " + res); if (quotient > 0) { res = ToString(quotient) + res; } return res; } public static uint FromString(string s) { uint res = 0; if (s.Length > 0) { for (int i = 0; i < s.Length; i++) { uint pow = UIntPow(32, (uint)i); // Debug.Log(); res += ((uint)CHARS.IndexOf(s[s.Length - 1 - i])) * pow; // Debug.Log(i + ":" + pow + " | " + s[i] + " " + CHARS.IndexOf(s[s.Length - 1 - i]) + " > " + res); } } return res; } private static uint UIntPow(uint x, uint pow) { uint ret = 1; while (pow != 0) { if ((pow & 1) == 1) ret *= x; x *= x; pow >>= 1; } return ret; } }