mirror of https://github.com/ArduPilot/ardupilot
AP_Common: Integrate methods for converting hexadecimal characters to numbers
Co-authored-by: muramura <ma2maru@gmail.com>
This commit is contained in:
parent
e4ca54b2e4
commit
1e26441ae6
|
@ -93,9 +93,9 @@ size_t strncpy_noterm(char *dest, const char *src, size_t n)
|
||||||
* return the numeric value of an ascii hex character
|
* return the numeric value of an ascii hex character
|
||||||
*
|
*
|
||||||
* @param[in] a Hexadecimal character
|
* @param[in] a Hexadecimal character
|
||||||
* @return Returns a binary value
|
* @return Returns a binary value. If 'a' is not a valid hex character 255 (AKA -1) is returned
|
||||||
*/
|
*/
|
||||||
int16_t char_to_hex(char a)
|
uint8_t char_to_hex(char a)
|
||||||
{
|
{
|
||||||
if (a >= 'A' && a <= 'F') {
|
if (a >= 'A' && a <= 'F') {
|
||||||
return a - 'A' + 10;
|
return a - 'A' + 10;
|
||||||
|
@ -104,5 +104,5 @@ int16_t char_to_hex(char a)
|
||||||
} else if (a >= '0' && a <= '9') {
|
} else if (a >= '0' && a <= '9') {
|
||||||
return a - '0';
|
return a - '0';
|
||||||
}
|
}
|
||||||
return 0;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ bool hex_to_uint8(uint8_t a, uint8_t &res); // return the uint8 value of an asc
|
||||||
size_t strncpy_noterm(char *dest, const char *src, size_t n);
|
size_t strncpy_noterm(char *dest, const char *src, size_t n);
|
||||||
|
|
||||||
// return the numeric value of an ascii hex character
|
// return the numeric value of an ascii hex character
|
||||||
int16_t char_to_hex(char a);
|
uint8_t char_to_hex(char a);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Bit manipulation
|
Bit manipulation
|
||||||
|
|
Loading…
Reference in New Issue