4ビットの個々のグループを1文字に変換する必要があります。テーブル付き:
char Hex[16]={ '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
これを計算する一般的な方法(2つのBASE間のライブラリなし)は次のとおりです。
ステップ1)
my_number = 0; // start to read digits.
while((a = read_digit(BASE))>=0) {
// read_digit should return -1 for non digit
my_number=my_number * BASE + a;
// optionally: if (count++ == 4) break; /* read only 4 bits or digits */
}
ステップ2)
// convert my_number to another base (eg. hex or decimal or octal or Base64)
// by repeated division by BASE and storing the modulus
while (my_number) {
int modulus = my_number % BASE;
my_number/=BASE;
PUSH(modulus);
}
ステップ2.5)
// Pop the numbers in range (0..BASE-1) from stack
// to output them from left to right
while (POP(my_number) >=0) { // assumes that pop returns <0 when empty
cout << myTable[my_number]; // this can be selected for any base
}