Keyple Util C++ Library 2.3.0.5-SNAPSHOT
Reference Terminal Reader API for C++
Static Public Member Functions | List of all members
keyple::core::util::HexUtil Class Referencefinal

#include <HexUtil.h>

Static Public Member Functions

static bool isValid (const std::string &hex)
 
static const std::vector< uint8_t > toByteArray (const std::string &hex)
 
static uint8_t toByte (const std::string &hex)
 
static uint16_t toShort (const std::string &hex)
 
static uint32_t toInt (const std::string &hex)
 
static uint64_t toLong (const std::string &hex)
 
static const std::string toHex (const std::vector< uint8_t > &tab)
 
static const std::string toHex (const uint8_t val)
 
static const std::string toHex (const uint16_t val)
 
static const std::string toHex (const uint32_t val)
 
static const std::string toHex (const uint64_t val)
 

Detailed Description

Definition at line 26 of file HexUtil.h.

Member Function Documentation

◆ isValid()

bool keyple::core::util::HexUtil::isValid ( const std::string &  hex)
static

Checks if a string is formed by an even number of hexadecimal digits.

  • "1234AB"
    will match.
  • "1234AB2"
    ,
    "12 34AB"
    or
    "x1234AB"
    won't match.
Parameters
hexThe string to check.
Returns
True if the string matches the expected hexadecimal representation, false otherwise.
Since
2.1.0

Definition at line 66 of file HexUtil.cpp.

◆ toByte()

uint8_t keyple::core::util::HexUtil::toByte ( const std::string &  hex)
static

Converts a hexadecimal string to a "byte".

Note: if the hexadecimal string contains more than two characters, then only the last two characters will be taken into account. In this case, please note that the conversion processing will be less performant.

Caution: the result may be erroneous if the string does not contain only hexadecimal characters.

Parameters
hexThe hexadecimal string to convert.
Returns
0 if the input string is empty.
Since
2.1.0

Definition at line 97 of file HexUtil.cpp.

◆ toByteArray()

const std::vector< uint8_t > keyple::core::util::HexUtil::toByteArray ( const std::string &  hex)
static

Converts a hexadecimal string to a byte array.

Caution: the result may be erroneous if the string does not contain only hexadecimal characters.

Parameters
hexThe hexadecimal string to convert.
Returns
An empty byte array if the input string is empty.
Exceptions
StringIndexOutOfBoundsExceptionIf the input string is made of an odd number of characters.
Since
2.1.0

Definition at line 81 of file HexUtil.cpp.

◆ toHex() [1/5]

const std::string keyple::core::util::HexUtil::toHex ( const std::vector< uint8_t > &  tab)
static

Converts a byte array to a hexadecimal string.

Parameters
tabThe byte array to convert.
Returns
A string with a size equal to (2 * size of the input array).
Since
2.1.0

Definition at line 145 of file HexUtil.cpp.

◆ toHex() [2/5]

const std::string keyple::core::util::HexUtil::toHex ( const uint16_t  val)
static

Converts a "short" to a hexadecimal string.

Note: the returned string has an even length and is left truncated if necessary to keep only the significant characters.

Parameters
valThe short to convert.
Returns
A string containing 2 or 4 characters.
Since
2.1.0

Definition at line 161 of file HexUtil.cpp.

◆ toHex() [3/5]

const std::string keyple::core::util::HexUtil::toHex ( const uint32_t  val)
static

Converts an "integer" to a hexadecimal string.

Note: the returned string has an even length and is left truncated if necessary to keep only the significant characters.

Parameters
valThe integer to convert.
Returns
A string containing 2, 4, 6 or 8 characters.
Since
2.1.0

Definition at line 170 of file HexUtil.cpp.

◆ toHex() [4/5]

const std::string keyple::core::util::HexUtil::toHex ( const uint64_t  val)
static

Converts a "long" to a hexadecimal string.

Note: the returned string has an even length and is left truncated if necessary to keep only the significant characters.

Parameters
valThe long to convert.
Returns
A string containing 2, 4, 6, 8, 10, 12, 14 or 16 characters.
Since
2.1.0

Definition at line 189 of file HexUtil.cpp.

◆ toHex() [5/5]

const std::string keyple::core::util::HexUtil::toHex ( const uint8_t  val)
static

Converts a "byte" to a hexadecimal string.

Parameters
valThe byte to convert.
Returns
A string containing 2 characters.
Since
2.1.0

Definition at line 156 of file HexUtil.cpp.

◆ toInt()

uint32_t keyple::core::util::HexUtil::toInt ( const std::string &  hex)
static

Converts a hexadecimal string to an "integer".

Note: if the hexadecimal string contains more than eight characters, then only the last eight characters will be taken into account. In this case, please note that the conversion processing will be less performant.

Caution: the result may be erroneous if the string does not contain only hexadecimal characters.

Parameters
hexThe hexadecimal string to convert.
Returns
0 if the input string is empty.
Since
2.1.0

Definition at line 121 of file HexUtil.cpp.

◆ toLong()

uint64_t keyple::core::util::HexUtil::toLong ( const std::string &  hex)
static

Converts a hexadecimal string to a "long".

Note: if the hexadecimal string contains more than sixteen characters, then only the last sixteen characters will be taken into account. In this case, please note that the conversion processing will be less performant.

Caution: the result may be erroneous if the string does not contain only hexadecimal characters.

Parameters
hexThe hexadecimal string to convert.
Returns
0 if the input string is empty.
Since
2.1.0

Definition at line 133 of file HexUtil.cpp.

◆ toShort()

uint16_t keyple::core::util::HexUtil::toShort ( const std::string &  hex)
static

Converts a hexadecimal string to a "short".

Note: if the hexadecimal string contains more than four characters, then only the last four characters will be taken into account. In this case, please note that the conversion processing will be less performant.

Caution: the result may be erroneous if the string does not contain only hexadecimal characters.

Parameters
hexThe hexadecimal string to convert.
Returns
0 if the input string is empty.
Exceptions
NullPointerExceptionIf the input string is null.
Since
2.1.0

Definition at line 109 of file HexUtil.cpp.


The documentation for this class was generated from the following files: