Routines for converting between byte arrays and hex strings. More...
Go to the source code of this file.
Functions | |
void | TMR_bytesToHex (const uint8_t *bytes, uint32_t size, char *hex) |
void | TMR_hexDottedQuad (const uint8_t bytes[4], char buf[12]) |
TMR_Status | TMR_hexDottedQuadToUint32 (const char bytes[12], uint32_t *result) |
TMR_Status | TMR_hexToBytes (const char *hex, uint8_t *bytes, uint32_t size, uint32_t *convertLen) |
Variables | |
static char | hexchars [] = "0123456789ABCDEF" |
Routines for converting between byte arrays and hex strings.
Definition in file hex_bytes.c.
void TMR_bytesToHex | ( | const uint8_t * | bytes, |
uint32_t | size, | ||
char * | hex | ||
) |
Convert an array of bytes, such as a tag EPC, into a hexadecimal string.
bytes | The byte array to convert. | |
size | The length of the byte array to convert. | |
[out] | hex | The converted hexadecimal string, null-terminated. |
Definition at line 83 of file hex_bytes.c.
void TMR_hexDottedQuad | ( | const uint8_t | bytes[4], |
char | buf[12] | ||
) |
Convert a four-byte array into a null-terminated string with the format %02X.%02X.%02X.%02X (AA.BB.CC.DD).
bytes | The array of four bytes to convert |
buf | The string to write to. Must be at least 12 bytes. |
Definition at line 103 of file hex_bytes.c.
TMR_Status TMR_hexDottedQuadToUint32 | ( | const char | bytes[12], |
uint32_t * | result | ||
) |
Convert a 12-byte null-terminated string hexDottedQuad into a uint32_t
bytes | The array of twelve bytes to convert |
result | The resulting uint32_t |
Definition at line 125 of file hex_bytes.c.
TMR_Status TMR_hexToBytes | ( | const char * | hex, |
uint8_t * | bytes, | ||
uint32_t | size, | ||
uint32_t * | convertLen | ||
) |
Convert a hexadecimal string into an array of bytes. The string may optionally include a "0x" prefix, which will be ignored.
hex | The hexadecimal string to convert. | |
[out] | bytes | The array to store the converted bytes. |
size | The length of the byte array to store into. | |
[out] | convertLen | The number of bytes written to the array, or NULL . |
If hex string is empty, *bytes should not be altered.
*convertLen is set to the correct value.
Function works when convertLen is NULL
.
Specific values: "00"
, "0000"
, "ffff"
, "0xffff"
, "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabb"
.
Definition at line 40 of file hex_bytes.c.
char hexchars[] = "0123456789ABCDEF" [static] |
Definition at line 36 of file hex_bytes.c.