Помогите создать блок отправки данных.
А случайно не коды ли ASCII. В любом случае это обозначение 16 тиричной системы исчисления
Код: Выделить всё
//оригинал
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;
}
// лёгкое редактирование
unsigned int hexToDec(String hexString) {
unsigned int decValue = 0;
int nextInt;
int abc = hexString.length(); // вычислим один раз длинну строки, а не в каждой итерации цикла :)
for( int i = 0; i < abc; i++) {
nextInt = int(hexString.charAt(i));
if (nextInt >= 48 && nextInt <= 57) nextInt -=48; // вместо nextInt = map(nextInt, 48, 57, 0, 9);
if (nextInt >= 65 && nextInt <= 70) nextInt -=50; // вместо nextInt = map(nextInt, 65, 70, 10, 15);
if (nextInt >= 97 && nextInt <= 102) nextInt -=80; // вместо nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);
decValue = (decValue * 16) + nextInt;
}
return decValue;
}
иногда реально напрягает, особенно с битовыми операциями