数字で少し遊んだ後、最終的に解決策を見つけました。の場合883.736
:
883.736 / 96 = 9.205 R: 56
9.205 / 96 = 95 R: 85
95 / 96 = 0 R: 95
これらの数値は、7 ビット ワードに変換できます。元の値を取得するには:
883.736 = 56 * 96^0 + 85 * 96^1 + 95 * 96^2
C# で表現されたアルゴリズム (リトルエンディアン):
public static class Base96
{
private const int BASE = 96;
public static byte[] Encode(int number)
{
var list = new List<Byte>();
do
{
list.Add((byte)(number % BASE));
}
while ((number = (number / BASE)) > 0);
return list.ToArray();
}
public static int Decode(byte[] words)
{
int result = 0;
for (int i = 0; i < words.Length; i++)
{
result += (words[i] * (int)Math.Pow(BASE, i));
}
return result;
}
}
次のように呼び出します。
var encoded = Base96.Encode(883736);
var decoded = Base96.Decode(encoded);