手机受到一条英文短信,如何将UD中数据转成ASCii?

解决方案 »

  1.   

    我用 bcb5 写的7位字符串编码、解码的函数:hellohello -> E8329BFD4697D9EC37 互转没有问题。
    AnsiString bit7encode(AnsiString input)
    {
        int i, j, len, cur;
        AnsiString text, hex, ret;
        char chm, chn;    len = input.Length();
        text = input;    i = 1; j = 0;
        while (i <= len)
        {
            chm = text[i];        if (i < len)
            {
                chn = text[i + 1];
                cur = (chm >> j ) | ((chn << (7-j)) & 0xff);
            }
            else
                cur = (chm >> j ) & 0x7f;        hex = IntToHex(cur, 2); ret = ret + hex;
    i++;
    j = (j + 1) % 7;
    if (j == 0)
    i++;
        }
        return ret;
    }AnsiString bit7decode(AnsiString input)
    {
        AnsiString ret, text;
        char hex, hey;
        unsigned char chm, chn;
        int i, j, len;
        int debug;    AnsiString tp;    len = input.Length();
        text = input;
        j = 0;
        for (i = 1; i <= len; i+=2)
        {
            chm = StrToInt("0x" + text.SubString(i, 2));        if (i > 1)
                chn = StrToInt("0x" + text.SubString(i - 2, 2));        if (j == 0)
            {
                hex = chm & 0x7f;
                if (i > 1)
                {
                    hey = chn >> 1;
                    ret += hey;
                }
            }
            else
            {
                hex = ((chm << j) | (chn >> (8 - j))) & 0x7f;
            }
        j = (j + 1) % 7;        ret += hex ;
        }
        return ret;
    }