7位转8位解码

    技术2022-05-11  96

    AnsiString Decode(AnsiString inputstr){int y;   //在短消息数据中的实际的数据长度short int chrChange=0;  //int j=0;char ptrTemp[200]={0};char *ptrSMS;unsigned char chrToSave,chrToNext,chrTemp;AnsiString DecodeStr;

    for(int i=1; i < inputstr.Length()+1; i += 2){  AnsiString TempStr = "0x" + inputstr.SubString(i,2);  DecodeStr += AnsiString((char)(TempStr.ToInt()));}

    ptrSMS = DecodeStr.c_str();y=DecodeStr.Length();

    for(int i=0;i<y;i++) //循环体内的程序段用来将短消息数据中的7比特编码数据转换成为英文或数字的UNICODE码{    chrTemp=*ptrSMS++;      //提取需要解码的字符数据    j=j%7;  //j用来表明当前字节左移几个比特    chrToSave=(chrTemp&(0x7f>>j))<<j;  //取出当前字节的0-j个比特,并左移j位    chrToNext=chrTemp&((0x7f>>j)^0xff);  //取出当前字节的高(j+1)位    ptrTemp[i]=chrToSave|chrChange;   //得到某个英文或阿拉伯数字    j++;    chrChange=chrToNext>>(8-j);    //下一个字节要做变换的低(8-j)个字节    if(j==7)        //如果j=7,表示每7个字节做完变换后就会多出一个字节的数据    {        ptrTemp[++i]=chrChange;          //多出一个字节的数据刚好是移位后的数据        chrChange=0;                     //chrChange清零        y++;                             //每遇到j=7,循环次数会减一次,加回去    }}return AnsiString(ptrTemp);} 


    最新回复(0)