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 ;
    }

你可能感兴趣的:(c++,c语言,开发语言)