美文网首页
2020-09-19

2020-09-19

作者: 懒生活 | 来源:发表于2020-09-19 07:25 被阅读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;
    }
    

    相关文章

      网友评论

          本文标题:2020-09-19

          本文链接:https://www.haomeiwen.com/subject/tnteyktx.html