diff --git a/libraries/AP_Common/AP_Common.cpp b/libraries/AP_Common/AP_Common.cpp index 3d749353fb..cfc2e5379a 100644 --- a/libraries/AP_Common/AP_Common.cpp +++ b/libraries/AP_Common/AP_Common.cpp @@ -83,3 +83,19 @@ void strncpy_noterm(char *dest, const char *src, size_t n) } 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'; +} diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index fe36858431..7d96284239 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -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); +// return the numeric value of an ascii hex character +int16_t char_to_hex(char a); + /* Bit manipulation */