2020-09-19

2020-09-19  本文已影响0人  懒生活
typedef unsigned long long bit64;
bit64 covertToBit(char str[12])
{
    char* pchar = str;
    bit64 tmp = 0;
    while (*pchar != 0)
    {
        tmp = tmp << 5;
        tmp += (*pchar - 'a' + 1);
        pchar++;
    }
    return tmp;
}

void covertToChar(bit64 bit, char str[12])
{
    bit64 mask = 0x1F;
    int i = 0;
    for (i = 0; i < 12; i++)
    {
        char tmp = bit & (mask << i * 5) >> i * 5;
        if (tmp == 0)
        {
            break;
        }
        str[i] = tmp - 1 + 'a';
    }
    str[i] = 0;
}


int main()
{
    bit64 test1 = covertToBit("abcdkjl");
    char ret[13];
    covertToChar(test1, ret);
    int i = 0;
}
上一篇下一篇

猜你喜欢

热点阅读