C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
CppUtilities::BE Namespace Reference

Encapsulates binary conversion functions using the big endian byte order. More...

Functions

CPP_UTILITIES_EXPORT constexpr std::int16_t toInt16 (const char *value)
 Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::uint16_t toUInt16 (const char *value)
 Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::int32_t toInt32 (const char *value)
 Returns a 32-bit signed integer converted from four bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t toUInt24 (const char *value)
 Returns a 32-bit unsigned integer converted from three bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t toUInt32 (const char *value)
 Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::int64_t toInt64 (const char *value)
 Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT constexpr std::uint64_t toUInt64 (const char *value)
 Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT float toFloat32 (const char *value)
 Returns a 32-bit floating point number converted from four bytes at a specified position in a char array.
 
CPP_UTILITIES_EXPORT double toFloat64 (const char *value)
 Returns a 64-bit floating point number converted from eight bytes at a specified position in a char array.
 
template<class T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
CPP_UTILITIES_EXPORTtoInt (const char *value)
 Returns the specified (unsigned) integer converted from the specified char array.
 
CPP_UTILITIES_EXPORT void getBytes24 (std::uint32_t value, char *outputbuffer)
 Stores the specified 24-bit unsigned integer value at a specified position in a char array.
 
template<class T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
CPP_UTILITIES_EXPORT void getBytes (T value, char *outputbuffer)
 Stores the specified (unsigned) integer value in a char array.
 
CPP_UTILITIES_EXPORT void getBytes (float value, char *outputbuffer)
 Stores the specified 32-bit floating point value at a specified position in a char array.
 
CPP_UTILITIES_EXPORT void getBytes (double value, char *outputbuffer)
 Stores the specified 64-bit floating point value at a specified position in a char array.
 

Detailed Description

Encapsulates binary conversion functions using the big endian byte order.

See also
Endianness - Wikipedia

Function Documentation

◆ getBytes() [1/3]

CPP_UTILITIES_EXPORT void CppUtilities::BE::getBytes ( double value,
char * outputbuffer )
inline

Stores the specified 64-bit floating point value at a specified position in a char array.

Definition at line 208 of file binaryconversion.h.

◆ getBytes() [2/3]

CPP_UTILITIES_EXPORT void CppUtilities::BE::getBytes ( float value,
char * outputbuffer )
inline

Stores the specified 32-bit floating point value at a specified position in a char array.

Definition at line 198 of file binaryconversion.h.

◆ getBytes() [3/3]

template<class T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
CPP_UTILITIES_EXPORT void CppUtilities::BE::getBytes ( T value,
char * outputbuffer )
inline

Stores the specified (unsigned) integer value in a char array.

Remarks
  • The value outputbuffer must point to a sequence of characters that is at least as long as the specified integer type.
  • This function is potentially faster than the width-specific toInt…() because the width-specific functions use custom code that may not be optimized by the compiler. (Only GCC optimized it but not Clang and MSVC.)

Definition at line 187 of file binaryconversion.h.

◆ getBytes24()

CPP_UTILITIES_EXPORT void CppUtilities::BE::getBytes24 ( std::uint32_t value,
char * outputbuffer )
inline

Stores the specified 24-bit unsigned integer value at a specified position in a char array.

Remarks
Ignores the most significant byte.

Definition at line 167 of file binaryconversion.h.

◆ toFloat32()

CPP_UTILITIES_EXPORT float CppUtilities::BE::toFloat32 ( const char * value)
inline

Returns a 32-bit floating point number converted from four bytes at a specified position in a char array.

Definition at line 128 of file binaryconversion.h.

◆ toFloat64()

CPP_UTILITIES_EXPORT double CppUtilities::BE::toFloat64 ( const char * value)
inline

Returns a 64-bit floating point number converted from eight bytes at a specified position in a char array.

Definition at line 138 of file binaryconversion.h.

◆ toInt()

template<class T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
CPP_UTILITIES_EXPORT T CppUtilities::BE::toInt ( const char * value)
inline

Returns the specified (unsigned) integer converted from the specified char array.

Remarks
  • The value must point to a sequence of characters that is at least as long as the specified integer type.
  • This function is potentially faster than the width-specific toInt…() because the width-specific functions use custom code that may not be optimized by the compiler. (Only GCC optimized it but not Clang and MSVC.) Note that the width-specific functions cannot be changed as they are constexpr and thus cannot use memcpy().

Definition at line 153 of file binaryconversion.h.

◆ toInt16()

CPP_UTILITIES_EXPORT constexpr std::int16_t CppUtilities::BE::toInt16 ( const char * value)
constexpr

Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.

Definition at line 24 of file binaryconversion.h.

◆ toInt32()

CPP_UTILITIES_EXPORT constexpr std::int32_t CppUtilities::BE::toInt32 ( const char * value)
constexpr

Returns a 32-bit signed integer converted from four bytes at a specified position in a char array.

Definition at line 48 of file binaryconversion.h.

◆ toInt64()

CPP_UTILITIES_EXPORT constexpr std::int64_t CppUtilities::BE::toInt64 ( const char * value)
constexpr

Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array.

Definition at line 92 of file binaryconversion.h.

◆ toUInt16()

CPP_UTILITIES_EXPORT constexpr std::uint16_t CppUtilities::BE::toUInt16 ( const char * value)
constexpr

Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array.

Definition at line 36 of file binaryconversion.h.

◆ toUInt24()

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::BE::toUInt24 ( const char * value)
constexpr

Returns a 32-bit unsigned integer converted from three bytes at a specified position in a char array.

Definition at line 64 of file binaryconversion.h.

◆ toUInt32()

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::BE::toUInt32 ( const char * value)
constexpr

Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array.

Definition at line 78 of file binaryconversion.h.

◆ toUInt64()

CPP_UTILITIES_EXPORT constexpr std::uint64_t CppUtilities::BE::toUInt64 ( const char * value)
constexpr

Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array.

Definition at line 110 of file binaryconversion.h.