# hex_bytes.c File Reference

Routines for converting between byte arrays and hex strings. More...

`#include <stdlib.h>`
`#include "tm_reader.h"`
`#include <pthread.h>`
`#include <semaphore.h>`
`#include <stdint.h>`
`#include <stdbool.h>`
`#include "tm_config.h"`
`#include "tmr_tag_protocol.h"`
`#include "tmr_gen2.h"`
`#include "tmr_iso180006b.h"`
`#include "tmr_tag_auth.h"`
`#include "tmr_tag_data.h"`
`#include "tmr_tagop.h"`
`#include "tmr_region.h"`
`#include "tmr_serial_transport.h"`
`#include "tmr_params.h"`
`#include "ltkc.h"`
`#include "tm_ltkc.h"`
`#include "tm_reader.h"`
`#include "tmr_status.h"`

## Functions

TMR_Status | TMR_hexToBytes (const char *hex, uint8_t *bytes, uint32_t size, uint32_t *convertLen)
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)

## Detailed Description

Routines for converting between byte arrays and hex strings.

Author:
  Nathan Williams

Date:
  10/23/2009

## Function Documentation

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.

Parameters:

  | bytes | The byte array to convert.
  | size | The length of the byte array to convert.
  `[out]` | hex | The converted hexadecimal string, null-terminated.

Test:
  If size is 0, *hex should point to an empty string.

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).

Parameters:

  | bytes | The array of four bytes to convert
  | buf | The string to write to. Must be at least 12 bytes.

TMR_Status TMR_hexDottedQuadToUint32 | ( | const char | bytes[12],
|  | uint32_t * | result |
| ) |  |  |

Convert a 12-byte null-terminated string hexDottedQuad into a uint32_t

Parameters:

  | bytes | The array of twelve bytes to convert
  | result | The resulting uint32_t

Returns:
  uint32_t represented but the 12 bytes

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.

Parameters:

  | 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`.

Test:

  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"`.