char 转换为 int

__int64 chartoint(unsigned char data)
{
 __int64 intdata;
 
 if ((data >= 0x30) && (data <= 0x39))
 {
  intdata = (data - 0x30) & 0x000000000000000F;
 }
 else if ((data >= 0x41) && (data <= 0x46))
 {
  intdata = (data - 0x37) & 0x000000000000000F;
 }
 else
 {
  return -1;
 }
 return intdata;
}

ViUInt64* dataint;

 for (int i=0; i< 1024*1024*4; ++i)
 {
  dataint[i] = (chartoint(databuf[i*16]) << 60) | (chartoint(databuf[i*16 + 1]) << 56)
          | (chartoint(databuf[i*16+2]) << 52) | (chartoint(databuf[i*16 + 3]) << 48)
       | (chartoint(databuf[i*16+4]) << 44) | (chartoint(databuf[i*16 + 5]) << 40)
       | (chartoint(databuf[i*16+6]) << 36) | (chartoint(databuf[i*16 + 7]) << 32)
       | (chartoint(databuf[i*16+8]) << 28) | (chartoint(databuf[i*16 + 9]) << 24)
       | (chartoint(databuf[i*16+10]) << 20) | (chartoint(databuf[i*16 + 11]) << 16)
       | (chartoint(databuf[i*16+12]) << 12) | (chartoint(databuf[i*16 + 13]) << 8)
       | (chartoint(databuf[i*16+14]) << 4) | (chartoint(databuf[i*16 + 15]));
 }

你可能感兴趣的:(char 转换为 int)