zoukankan      html  css  js  c++  java
  • 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进制保存到整型数组中。

  • 相关阅读:
    changing a pointer rather than erasing memory cells
    验证码识别 edge enhancement 轮廓增强 region finding 区域查找
    Manipulating Data Structures
    passing parameters by value is inefficient when the parameters represent large blocks of data
    Aliasing 走样
    Artificial Intelligence Research Methodologies 人工智能研究方法
    Thread safety
    include pointers as a primitive data type
    flat file
    functional cohesion
  • 原文地址:https://www.cnblogs.com/lobsterIT/p/4736402.html
Copyright © 2011-2022 走看看