标签:div 进制 move class span i++ hex 字符串 整数
1. 字符串中移除一个字符
1 void removeChar(char *str, char c) 2 { 3 char *s = str; 4 int j, k; 5 6 for(j=k=0; s[j]!=‘\0‘; j++) { 7 if(s[j]!=c) 8 s[k++]=s[j]; 9 } 10 11 s[k]= ‘\0‘; 12 }
2. 字符串转为16进制整数
1 unsigned int StrToHex(char *pszSrc, int nLen) 2 { 3 char h1, h2; 4 char s1, s2; 5 unsigned char pbDest; 6 unsigned int ret = 0; 7 8 //printf("%s, src: %s\n", __FUNCTION__, pszSrc); 9 10 for (int i = 0; i < nLen; i++) 11 { 12 h1 = pszSrc[2 * i]; 13 h2 = pszSrc[2 * i + 1]; 14 15 s1 = toupper(h1) - 0x30; 16 if (s1 > 9) 17 s1 -= 7; 18 19 s2 = toupper(h2) - 0x30; 20 if (s2 > 9) 21 s2 -= 7; 22 pbDest = s1 * 16 + s2; 23 //printf("h1: 0x%02x, h2: 0x%02x, s1: 0x%02x, s2: 0x%02x, dst: 0x%x\n", h1, h2, s1, s2, pbDest); 24 25 ret = (ret << 8) + pbDest; 26 //printf("ret: 0x%x\n", ret); 27 } 28 29 return ret; 30 }
标签:div 进制 move class span i++ hex 字符串 整数
原文地址:https://www.cnblogs.com/hiawind/p/9089168.html