0

ベース32ビットでデコードされた文字列が1つあります。その文字列をデコードしたいのですが、任意の文字列をベース32ビットでデコードされた文字列にエンコードしたいと思います。この問題を解決できるように、アルゴリズム(Cでも)またはそのためのAPIはありますか?よろしくお願いします。

4

1 に答える 1

0

あなたの質問を理解できるかどうかはわかりませんが、32を底とする数を10を底とする(10進数)数に変換したい場合は、次のようにしてください。

#include <stdio.h>                                                                                                                                          
#include <string.h>
#include <math.h>

#define BASE 32

unsigned int convert_number (const char *s) {
    unsigned int len = strlen(s) - 1;
    unsigned int result = 0;
    char start_ch = 0, ch;
    while(*s != '\0') {
        ch = *s;
        if (ch >= 'a') {
            start_ch = 'a' - 10;
        } else if (ch >= 'A') {
            start_ch = 'A' - 10;
        } else {
            start_ch = '0';
        }

        if(len >= 0)
            result += (ch - start_ch) * pow(BASE, len);
        else
            result += (ch - start_ch);
        ++s;
        --len;
    }

    return result;
}
于 2012-05-08T06:38:29.647 に答える