Static Public Member Functions

static ASPOSECPP_SHARED_API bool _IsLittleEndian ()
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (bool value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (char_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (int16_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (int value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (int64_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (uint16_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (uint32_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (uint64_t value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (float value)
 
static ASPOSECPP_SHARED_API System::ArrayPtr< uint8_t > GetBytes (double value)
 
static ASPOSECPP_SHARED_API bool ToBoolean (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API bool ToBoolean (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API char_t ToChar (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API char_t ToChar (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int16_t ToInt16 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int16_t ToInt16 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int ToInt32 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int ToInt32 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int64_t ToInt64 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API int64_t ToInt64 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint16_t ToUInt16 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint16_t ToUInt16 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint32_t ToUInt32 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint32_t ToUInt32 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint64_t ToUInt64 (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API uint64_t ToUInt64 (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API float ToSingle (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API float ToSingle (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API double ToDouble (const System::ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API double ToDouble (const System::Details::ArrayView< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API String ToString (const ArrayPtr< uint8_t > &value, bool uppercase=1, const String &separator=u"-")
 
static ASPOSECPP_SHARED_API String ToString (const ArrayPtr< uint8_t > &value, int startIndex)
 
static ASPOSECPP_SHARED_API String ToString (const ArrayPtr< uint8_t > &value, int startIndex, int length)
 
static ASPOSECPP_SHARED_API int64_t DoubleToInt64Bits (double value)
 
static ASPOSECPP_SHARED_API double Int64BitsToDouble (int64_t value)
 

Static Public Attributes

static const ASPOSECPP_SHARED_API bool IsLittleEndian
 

Detailed Description

Contains methods that perform conversions of sequence of bytes to a value type and vice-versa. This is a static type with no instance services. You should never create instances of it by any means.

#include <system/bit_converter.h>
#include <system/smart_ptr.h>
using namespace System;
template <typename T>
void Print(T arg)
{
std::cout << arg << ' ';
for (const auto byte: BitConverter::GetBytes(arg))
{
std::cout << std::hex << static_cast<int>(byte);
}
std::cout << std::endl;
}
int main()
{
// Create values to print.
int anInt = 1234567890;
double aDouble = 0.123456789;
// Print value and its bytes.
Print(anInt);
Print(aDouble);
return 0;
}
/*
* This code example produces the following output:
* 1234567890 d229649
* 0.123457 5f633937dd9abf3f
*/

Member Function Documentation

◆ _IsLittleEndian()

static ASPOSECPP_SHARED_API bool System::BitConverter::_IsLittleEndian ( )
static

Indicates the endianness of the current architecture.

Returns
true if the architecture is little endian, false otherwise

◆ DoubleToInt64Bits()

static ASPOSECPP_SHARED_API int64_t System::BitConverter::DoubleToInt64Bits ( double  value)
static

Returns a 64-bit integer value whose binary representation is equal to binary representation of the specified double-precision floating point value.

Parameters
valueThe double-precision floating point value
Returns
64-bit integer value whose binary representation is equal to that of the specified value

◆ GetBytes() [1/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( bool  value)
static

Converts the specified boolean value into an array of bytes.

Parameters
valueA boolean value to convert
Returns
1-byte array representing specified value

◆ GetBytes() [2/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( char_t  value)
static

Converts the specified char_t value into an array of bytes.

Parameters
valueA char_t value to convert
Returns
2-byte array representing specified value

◆ GetBytes() [3/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( int16_t  value)
static

Converts the specified 16-bit integer value into an array of bytes.

Parameters
valueA 16-bit integer value to convert
Returns
2-byte array representing specified value

◆ GetBytes() [4/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( int  value)
static

Converts the specified 32-bit integer value into an array of bytes.

Parameters
valueA 32-bit integer value to convert
Returns
4-byte array representing specified value

◆ GetBytes() [5/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( int64_t  value)
static

Converts the specified 64-bit integer value into an array of bytes.

Parameters
valueA 64-bit integer value to convert
Returns
8-byte array representing specified value

◆ GetBytes() [6/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( uint16_t  value)
static

Converts the specified unsigned 16-bit integer value into an array of bytes.

Parameters
valueAn unsigned 16-bit integer value to convert
Returns
2-byte array representing specified value

◆ GetBytes() [7/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( uint32_t  value)
static

Converts the specified unsigned 32-bit integer value into an array of bytes.

Parameters
valueAn unsigned 32-bit integer value to convert
Returns
4-byte array representing specified value

◆ GetBytes() [8/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( uint64_t  value)
static

Converts the specified unsigned 64-bit integer value into an array of bytes.

Parameters
valueAn unsigned 64-bit integer value to convert
Returns
8-byte array representing specified value

◆ GetBytes() [9/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( float  value)
static

Converts the specified single-precision floating-point value into an array of bytes.

Parameters
valueA floating-point value to convert
Returns
4-byte array representing specified value

◆ GetBytes() [10/10]

static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> System::BitConverter::GetBytes ( double  value)
static

Converts the specified double-precision floating-point value into an array of bytes.

Parameters
valueA floating-point value to convert
Returns
8-byte array representing specified value

◆ Int64BitsToDouble()

static ASPOSECPP_SHARED_API double System::BitConverter::Int64BitsToDouble ( int64_t  value)
static

Returns a double-precision floating point value whose value is equivalent to value

Parameters
value64-bit integer value whose binary representation is equal to that of the specified value
Returns
The double-precision floating point value

◆ ToBoolean() [1/2]

static ASPOSECPP_SHARED_API bool System::BitConverter::ToBoolean ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts one byte from the specified array starting at the specified index to boolean value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Boolean value resulting from conversion

◆ ToBoolean() [2/2]

static ASPOSECPP_SHARED_API bool System::BitConverter::ToBoolean ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts one byte from the specified array starting at the specified index to boolean value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Boolean value resulting from conversion

◆ ToChar() [1/2]

static ASPOSECPP_SHARED_API char_t System::BitConverter::ToChar ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to char_t value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
char_t value resulting from conversion

◆ ToChar() [2/2]

static ASPOSECPP_SHARED_API char_t System::BitConverter::ToChar ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to char_t value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
char_t value resulting from conversion

◆ ToDouble() [1/2]

static ASPOSECPP_SHARED_API double System::BitConverter::ToDouble ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to double-precision floating point value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Double-precision floating-point value resulting from conversion

◆ ToDouble() [2/2]

static ASPOSECPP_SHARED_API double System::BitConverter::ToDouble ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to double-precision floating point value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Double-precision floating-point value resulting from conversion

◆ ToInt16() [1/2]

static ASPOSECPP_SHARED_API int16_t System::BitConverter::ToInt16 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to 16-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
16-bit integer value resulting from conversion

◆ ToInt16() [2/2]

static ASPOSECPP_SHARED_API int16_t System::BitConverter::ToInt16 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to 16-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
16-bit integer value resulting from conversion

◆ ToInt32() [1/2]

static ASPOSECPP_SHARED_API int System::BitConverter::ToInt32 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to 32-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
32-bit integer value resulting from conversion

◆ ToInt32() [2/2]

static ASPOSECPP_SHARED_API int System::BitConverter::ToInt32 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to 32-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
32-bit integer value resulting from conversion

◆ ToInt64() [1/2]

static ASPOSECPP_SHARED_API int64_t System::BitConverter::ToInt64 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to 64-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
64-bit integer value resulting from conversion

◆ ToInt64() [2/2]

static ASPOSECPP_SHARED_API int64_t System::BitConverter::ToInt64 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to 64-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
64-bit integer value resulting from conversion

◆ ToSingle() [1/2]

static ASPOSECPP_SHARED_API float System::BitConverter::ToSingle ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to single-precision floating point value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Single-precision floating-point value resulting from conversion

◆ ToSingle() [2/2]

static ASPOSECPP_SHARED_API float System::BitConverter::ToSingle ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to single-precision floating point value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Single-precision floating-point value resulting from conversion

◆ ToString() [1/3]

static ASPOSECPP_SHARED_API String System::BitConverter::ToString ( const ArrayPtr< uint8_t > &  value,
bool  uppercase = 1,
const String separator = u"-" 
)
static

Converts all values of the specified byte array into their hexadecimal string representation. Case of letters to use in hexadecimal notation and separator inserted between each pair of neighbouring bytes are specified through corresponding arguments.

Parameters
valueArray that contains bytes to convert
uppercaseSpecifies the case of letters to use in resulting hexadecimal representation
separatorA string used as a separator inserted between each pair of neighbouring bytes in the resulting string
Returns
String containing hexadecimal representation of the specified byte array

◆ ToString() [2/3]

static ASPOSECPP_SHARED_API String System::BitConverter::ToString ( const ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts values of the specified byte array into their hexadecimal string representation starting at specified index.

Parameters
valueArray that contains bytes to convert
startIndexIndex in the specified array at which to start converting
Returns
String containing hexadecimal representation of the specified range of elements of the specified array

◆ ToString() [3/3]

static ASPOSECPP_SHARED_API String System::BitConverter::ToString ( const ArrayPtr< uint8_t > &  value,
int  startIndex,
int  length 
)
static

Converts a range of values of the specified byte array into their hexadecimal string representation.

Parameters
valueArray that contains bytes to convert
startIndexIndex in the specified array at which the range of the byte array elements to convert begins
lengthThe length of the range the byte array elements to convert
Returns
String containing hexadecimal representation of the specified range of elements of the specified array

◆ ToUInt16() [1/2]

static ASPOSECPP_SHARED_API uint16_t System::BitConverter::ToUInt16 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to unsigned 16-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 16-bit integer value resulting from conversion

◆ ToUInt16() [2/2]

static ASPOSECPP_SHARED_API uint16_t System::BitConverter::ToUInt16 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts two bytes from the specified array starting at the specified index to unsigned 16-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 16-bit integer value resulting from conversion

◆ ToUInt32() [1/2]

static ASPOSECPP_SHARED_API uint32_t System::BitConverter::ToUInt32 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to unsigned 32-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 32-bit integer value resulting from conversion

◆ ToUInt32() [2/2]

static ASPOSECPP_SHARED_API uint32_t System::BitConverter::ToUInt32 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts four bytes from the specified array starting at the specified index to unsigned 32-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 32-bit integer value resulting from conversion

◆ ToUInt64() [1/2]

static ASPOSECPP_SHARED_API uint64_t System::BitConverter::ToUInt64 ( const System::ArrayPtr< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to unsigned 64-bit integer value

Parameters
valueArray that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 64-bit integer value resulting from conversion

◆ ToUInt64() [2/2]

static ASPOSECPP_SHARED_API uint64_t System::BitConverter::ToUInt64 ( const System::Details::ArrayView< uint8_t > &  value,
int  startIndex 
)
static

Converts eight bytes from the specified array starting at the specified index to unsigned 64-bit integer value

Parameters
valueArrayView that contains bytes to convert
startIndexIndex in the array at which to start taking bytes for conversion
Returns
Unsigned 64-bit integer value resulting from conversion

Member Data Documentation

◆ IsLittleEndian

const ASPOSECPP_SHARED_API bool System::BitConverter::IsLittleEndian
static

Indicates the endianness of the current architecture. true if the architecture is little endian, false otherwise