C/C++字符串转字节流

C/C++字符串转字节流

/**

  • 字符串转字节流

  • @param source 输入字符串 dest 输出字符串 sourceLen 输入字符串长度
    /
    void myTools::HexStrToByte(const char
    source, unsigned char* dest, int sourceLen)
    {
    short i;
    unsigned char highByte, lowByte;

    for (i = 0; i < sourceLen; i += 2)
    {
    highByte = toupper(source[i]);
    lowByte = toupper(source[i + 1]);

      if (highByte > 0x39)
          highByte -= 0x37;
      else
          highByte -= 0x30;
    
      if (lowByte > 0x39)
          lowByte -= 0x37;
      else
          lowByte -= 0x30;
    
      dest[i / 2] = (highByte << 4) | lowByte;
    

    }
    return ;
    }

猜你喜欢

转载自blog.csdn.net/c13055215176/article/details/127101020