ascii码字符串转成整型数组
for(int buffer_len=1;buffer_len<m-1;buffer_len++,check_len++){ if(buffer[buffer_len]<=0x39){//第一位为‘0’-‘9’ WriteBuffer[check_len] = (buffer[buffer_len]-0x30)*16; buffer_len++; if(buffer[buffer_len]<=0x39){// 第二位'0'-'9' WriteBuffer[check_len] += (buffer[buffer_len]-0x30); // buffer_len++; }else if((buffer[buffer_len]<=0x46)&&(buffer[buffer_len]>=0x41)){//第二位 'A'-'F' WriteBuffer[check_len] += (buffer[buffer_len]-0x37); // buffer_len++; }else if((buffer[buffer_len]<=0x66)&&(buffer[buffer_len]>=0x61)){//'a'-'f' WriteBuffer[check_len] += (buffer[buffer_len]-0x57); // buffer_len++; } } else if(buffer[buffer_len]>=0x41&&buffer[buffer_len]<=0x46){//第一位 'A'-'F' WriteBuffer[check_len] = (buffer[buffer_len]-0x37)*16; buffer_len++; if(buffer[buffer_len]<=0x39){// 第二位'0'-'9' WriteBuffer[check_len] += (buffer[buffer_len]-0x30); // buffer_len++; }else if((buffer[buffer_len]<=0x46)&&(buffer[buffer_len]>=0x41)){//第二位 'A'-'F' WriteBuffer[check_len] += (buffer[buffer_len]-0x37); // buffer_len++; }else if((buffer[buffer_len]<=0x66)&&(buffer[buffer_len]>=0x61)){//'a'-'f' WriteBuffer[check_len] += (buffer[buffer_len]-0x57); // buffer_len++; } }else if((buffer[buffer_len]<=0x66)&&(buffer[buffer_len]>=0x61)){//'a'-'f' WriteBuffer[check_len] += (buffer[buffer_len]-0x57)*16; buffer_len++; if(buffer[buffer_len]<=0x39){// 第二位'0'-'9' WriteBuffer[check_len] += (buffer[buffer_len]-0x30); // buffer_len++; }else if((buffer[buffer_len]<=0x46)&&(buffer[buffer_len]>=0x41)){//第二位 'A'-'F' WriteBuffer[check_len] += (buffer[buffer_len]-0x37); // buffer_len++; }else if((buffer[buffer_len]<=0x66)&&(buffer[buffer_len]>=0x61)){//'a'-'f' WriteBuffer[check_len] += (buffer[buffer_len]-0x57); // buffer_len++; } } }
上面的程序是将一个字符串转换成数,在ascii编码的时候用到的,用于取得数字,做校验位的
例:
char tmp[20]="ff70603130FF";
两位两位的取值 将ff取出转换成16进制或10进制保存到整型数组中。