0x30是什么意思呢 0x30等于十进制的48,48也是0的ASCII值,,1-9的ASCII值是49-57,,所以某一个值-0x30,,就是将字符0-9转换为0-9 ‘0’~’9′ -0x30 变成 0~9 WrComLCD(0xc0+6); WrDatLCD(0x30+second/10); WrComLCD(0xc0+7); WrDatLCD(0x30+second%10); //字节流转换为十六进制字符串 void ByteToHexStr(const unsigned char* source, char* dest, int sourceLen) { short i; unsigned char highByte, lowByte; for (i = 0; i < sourceLen; i++) { highByte = source[i] >> 4; lowByte = source[i] & 0x0f ; highByte += 0x30; if (highByte > 0x39) dest[i * 2] = highByte + 0x07; else dest[i * 2] = highByte; lowByte += 0x30; if (lowByte > 0x39) dest[i * 2 + 1] = lowByte + 0x07; else dest[i * 2 + 1] = lowByte; } return ; } //字节流转换为十六进制字符串的另一种实现方式 void Hex2Str( const char *sSrc, char *sDest, int nSrcLen ) { int i; char szTmp[3]; for( i = 0; i < nSrcLen; i++ ) { sprintf( szTmp, "%02X", (unsigned char) sSrc[i] ); memcpy( &sDest[i * 2], szTmp, 2 ); } return ; } //十六进制字符串转换为字节流 void 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 ; } 声明:本站所有内容,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。 收藏 链接