0

需要从字节值转换为 DWORD(基于 ascii)!

例子:

输入:(1F 12 BA 43保存在std::vector<BYTE>

输出:(31 46 31 32 42 41 34 33输入的ascii值)->也存储在一个std::vector<BYTE>

进行这种转换的最简单方法是什么?

谢谢

4

1 回答 1

1
typedef unsigned char BYTE;
typedef std::vector<BYTE> Vector;

Vector hex2ascii(Vector const &src) {
  Vector result;
  for ( Vector::const_iterator iter = src.begin(); iter!=src.end(); iter++ ) {
    BYTE item = *iter;
    unsigned bits=8;
    do {
      bits -= 4;
      result.push_back("0123456789ABCDEF"[(item>>bits)&15u]);
    } while(bits);
  }
  return result;
}
于 2014-12-22T07:23:19.667 回答