0~9这几个很容易转成int,但是像“Hello”你怎么转呢?
这里有个16进制int的字符串转成10进制的程序,包含了10进制的字符串转换部分,试过可用
- unsigned int hexToDec(String hexString) {
- unsigned int decValue = 0;
- int nextInt;
- for (int i = 0; i < hexString.length(); i++) {
- nextInt = int(hexString.charAt(i));
- if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
- if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
- if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
- nextInt = constrain(nextInt, 0, 15);
- decValue = (decValue * 16) + nextInt;
- }
- return decValue;
- }
复制代码 |