AP_Common: Make the char_to_hex method a common method

This commit is contained in:
murata 2021-11-03 09:09:08 +09:00 committed by Andrew Tridgell
parent 8743ca226c
commit 1e91dfe9d6
2 changed files with 19 additions and 0 deletions

View File

@ -83,3 +83,19 @@ void strncpy_noterm(char *dest, const char *src, size_t n)
} }
memcpy(dest, src, len); memcpy(dest, src, len);
} }
/**
* return the numeric value of an ascii hex character
*
* @param[in] a Hexadecimal character
* @return Returns a binary value
*/
int16_t char_to_hex(char a)
{
if (a >= 'A' && a <= 'F')
return a - 'A' + 10;
else if (a >= 'a' && a <= 'f')
return a - 'a' + 10;
else
return a - '0';
}

View File

@ -149,6 +149,9 @@ bool hex_to_uint8(uint8_t a, uint8_t &res); // return the uint8 value of an asc
*/ */
void strncpy_noterm(char *dest, const char *src, size_t n); void strncpy_noterm(char *dest, const char *src, size_t n);
// return the numeric value of an ascii hex character
int16_t char_to_hex(char a);
/* /*
Bit manipulation Bit manipulation
*/ */