xtd 0.2.0
bit_converter.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "core_export.hpp"
6#include "array.hpp"
7#include "enum.hpp"
8#include "read_only_span.hpp"
9#include "static.hpp"
10#include "types.hpp"
11
13namespace xtd {
53 private:
54 static constexpr uint32 __endian_value__ = 0x01020304;
55 static constexpr xtd::byte __endian_query__ = static_cast<const xtd::byte&>(__endian_value__);
56
57 public:
60 enum class endian {
65 };
66
68
76 static constexpr bool is_big_endian = __endian_query__ == 0x01u;
83 static constexpr bool is_little_endian = __endian_query__ == 0x04u;
92
94
103 static int64 double_to_int64_bits(double value) noexcept;
104
111 static xtd::array<xtd::byte> get_bytes(bool value) noexcept;
112
119 static xtd::array<xtd::byte> get_bytes(char value) noexcept;
120
127 static xtd::array<xtd::byte> get_bytes(char8 value) noexcept;
128
135 static xtd::array<xtd::byte> get_bytes(char16 value) noexcept;
136
143 static xtd::array<xtd::byte> get_bytes(char32 value) noexcept;
144
151 static xtd::array<xtd::byte> get_bytes(wchar value) noexcept;
152
159 static xtd::array<xtd::byte> get_bytes(double value) noexcept;
160
164 static xtd::array<xtd::byte> get_bytes(sbyte value) noexcept;
165
172 static xtd::array<xtd::byte> get_bytes(int16 value) noexcept;
173
180 static xtd::array<xtd::byte> get_bytes(int32 value) noexcept;
181
188 static xtd::array<xtd::byte> get_bytes(int64 value) noexcept;
189
196 static xtd::array<xtd::byte> get_bytes(float value) noexcept;
197
202
209 static xtd::array<xtd::byte> get_bytes(uint16 value) noexcept;
210
217 static xtd::array<xtd::byte> get_bytes(uint32 value) noexcept;
218
225 static xtd::array<xtd::byte> get_bytes(uint64 value) noexcept;
226
228 static xtd::array<xtd::byte> get_bytes(slong value) noexcept;
229 static xtd::array<xtd::byte> get_bytes(xtd::ulong value) noexcept;
231
236 static float int32_bits_to_single(int32 value) noexcept;
237
242 static double int64_bits_to_double(int64 value) noexcept;
243
248 static int32 single_to_int32_bits(float value) noexcept;
249
259 static bool to_boolean(const xtd::array<xtd::byte>& value, xtd::size start_index);
269 static bool to_boolean(const read_only_span<xtd::byte>& value, xtd::size start_index);
270
279 static char32 to_char(const xtd::array<xtd::byte>& value, xtd::size start_index);
288 static char32 to_char(const read_only_span<xtd::byte>& value, xtd::size start_index);
289
298 static double to_double(const xtd::array<xtd::byte>& value, xtd::size start_index);
307 static double to_double(const read_only_span<xtd::byte>& value, xtd::size start_index);
308
317 static int16 to_int16(const xtd::array<xtd::byte>& value, xtd::size start_index);
326 static int16 to_int16(const read_only_span<xtd::byte>& value, xtd::size start_index);
327
336 static int32 to_int32(const xtd::array<xtd::byte>& value, xtd::size start_index);
345 static int32 to_int32(const read_only_span<xtd::byte>& value, xtd::size start_index);
346
355 static int64 to_int64(const xtd::array<xtd::byte>& value, xtd::size start_index);
364 static int64 to_int64(const read_only_span<xtd::byte>& value, xtd::size start_index);
365
374 static float to_single(const xtd::array<xtd::byte>& value, xtd::size start_index);
383 static float to_single(const read_only_span<xtd::byte>& value, xtd::size start_index);
384
393 static uint16 to_uint16(const xtd::array<xtd::byte>& value, xtd::size start_index);
402 static uint16 to_uint16(const read_only_span<xtd::byte>& value, xtd::size start_index);
403
412 static uint32 to_uint32(const xtd::array<xtd::byte>& value, xtd::size start_index);
421 static uint32 to_uint32(const read_only_span<xtd::byte>& value, xtd::size start_index);
422
431 static uint64 to_uint64(const xtd::array<xtd::byte>& value, xtd::size start_index);
440 static uint64 to_uint64(const read_only_span<xtd::byte>& value, xtd::size start_index);
441
450 static xtd::size to_size(const xtd::array<xtd::byte>& value, xtd::size start_index);
459 static xtd::size to_size(const read_only_span<xtd::byte>& value, xtd::size start_index);
460
479
490 static xtd::string to_string(const xtd::array<xtd::byte>& value, xtd::size start_index);
501 static xtd::string to_string(const read_only_span<xtd::byte>& value, xtd::size start_index);
502
532 };
533}
534
536template<> struct xtd::enum_register<xtd::bit_converter::endian> {
537 explicit operator auto() const noexcept {return xtd::enum_collection<xtd::bit_converter::endian> {{xtd::bit_converter::endian::little, "little"}, {xtd::bit_converter::endian::big, "big"}};}
538};
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Converts base data types to an xtd::array of bytes, and an xtd::array of bytes to base data types.
Definition bit_converter.hpp:52
static int32 to_int32(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static uint64 to_uint64(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 64-bit unsigned integer converted from two bytes at a specified position in a xtd::byte xtd...
static int32 to_int32(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static uint16 to_uint16(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a xtd::byte xtd...
static constexpr bool is_little_endian
Indicates the xtd::byte order ("endianness") in which data is stored in this computer architecture.
Definition bit_converter.hpp:83
static float int32_bits_to_single(int32 value) noexcept
Converts the specified 32-bit signed integer to a single-precision floating point number.
static int64 to_int64(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 64-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static xtd::array< xtd::byte > get_bytes(wchar value) noexcept
Returns the specified wchar value as an xtd::array of bytes.
static uint64 to_uint64(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 64-bit unsigned integer converted from two bytes at a specified position in a xtd::byte xtd...
static xtd::array< xtd::byte > get_bytes(uint16 value) noexcept
Returns the specified uint16 value as an xtd::array of bytes.
static int64 double_to_int64_bits(double value) noexcept
Converts the specified double-precision floating point number to a 64-bit signed integer.
static xtd::array< xtd::byte > get_bytes(int32 value) noexcept
Returns the specified int32 value as an xtd::array of bytes.
static xtd::string to_string(const read_only_span< xtd::byte > &value, xtd::size start_index)
Converts the numeric value of each element of a specified sub xtd::array of bytes to its equivalent h...
static int16 to_int16(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 16-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static xtd::string to_string(const read_only_span< xtd::byte > &value)
Converts the numeric value of each element of a specified xtd::array of bytes to its equivalent hexad...
static int16 to_int16(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 16-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static uint32 to_uint32(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static bool to_boolean(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a Boolean value converted from one xtd::byte at a specified position in a xtd::byte xtd::arra...
static xtd::string to_string(const xtd::array< xtd::byte > &value)
Converts the numeric value of each element of a specified xtd::array of bytes to its equivalent hexad...
static xtd::array< xtd::byte > get_bytes(float value) noexcept
Returns the specified single value as an xtd::array of bytes.
static xtd::size to_size(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a xtd::size converted from two bytes at a specified position in a xtd::byte xtd::array.
static xtd::array< xtd::byte > get_bytes(sbyte value) noexcept
Returns the specified xtd::byte value as an xtd::array of bytes.
static double to_double(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a double-precision floating point number converted from eight bytes at a specified position i...
static xtd::array< xtd::byte > get_bytes(xtd::byte value) noexcept
Returns the specified xtd::byte value as an xtd::array of bytes.
static constexpr bool is_big_endian
Indicates the xtd::byte order ("endianness") in which data is stored in this computer architecture.
Definition bit_converter.hpp:76
static constexpr endian endianness
Indicates the xtd::byte order ("endianness") in which data is stored in this computer architecture.
Definition bit_converter.hpp:90
static xtd::array< xtd::byte > get_bytes(uint64 value) noexcept
Returns the specified uint64 value as an xtd::array of bytes.
static xtd::array< xtd::byte > get_bytes(double value) noexcept
Returns the specified double value as an xtd::array of bytes.
static xtd::array< xtd::byte > get_bytes(char32 value) noexcept
Returns the specified xtd::char32 value as an xtd::array of bytes.
endian
Represents the xtd::byte order ("endianness") in which data is stored in this computer architecture.
Definition bit_converter.hpp:60
@ little
Represnets "Little-endian" order.
Definition bit_converter.hpp:62
@ big
Represnets "Big-endian" order.
Definition bit_converter.hpp:64
static xtd::array< xtd::byte > get_bytes(int16 value) noexcept
Returns the specified int16 value as an xtd::array of bytes.
static uint16 to_uint16(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a xtd::byte xtd...
static xtd::string to_string(const xtd::array< xtd::byte > &value, xtd::size start_index, xtd::size length)
Converts the numeric value of each element of a specified sub xtd::array of bytes to its equivalent h...
static int32 single_to_int32_bits(float value) noexcept
Converts the specified single-precision floating point number to a 32-bit signed integer.
static char32 to_char(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a char32 converted from two bytes at a specified position in a xtd::byte xtd::array.
static xtd::array< xtd::byte > get_bytes(char value) noexcept
Returns the specified char value as an xtd::array of bytes.
static xtd::array< xtd::byte > get_bytes(char8 value) noexcept
Returns the specified xtd::char8 value as an xtd::array of bytes.
static char32 to_char(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a char32 converted from two bytes at a specified position in a xtd::byte xtd::read_only_span.
static float to_single(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a single-precision floating point number converted from eight bytes at a specified position i...
static int64 to_int64(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 64-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static xtd::string to_string(const read_only_span< xtd::byte > &value, xtd::size start_index, xtd::size length)
Converts the numeric value of each element of a specified sub xtd::array of bytes to its equivalent h...
static double to_double(const xtd::array< xtd::byte > &value, xtd::size start_index)
Returns a double-precision floating point number converted from eight bytes at a specified position i...
static double int64_bits_to_double(int64 value) noexcept
Converts the specified 64-bit signed integer to a double-precision floating point number.
static uint32 to_uint32(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte xtd::...
static xtd::string to_string(const xtd::array< xtd::byte > &value, xtd::size start_index)
Converts the numeric value of each element of a specified sub xtd::array of bytes to its equivalent h...
static bool to_boolean(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a Boolean value converted from one xtd::byte at a specified position in a xtd::byte xtd::read...
static xtd::size to_size(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a sxtd::ize converted from two bytes at a specified position in a xtd::byte xtd::read_only_sp...
static xtd::array< xtd::byte > get_bytes(int64 value) noexcept
Returns the specified int64 value as an xtd::array of bytes.
static xtd::array< xtd::byte > get_bytes(uint32 value) noexcept
Returns the specified uint32 value as an xtd::array of bytes.
static float to_single(const read_only_span< xtd::byte > &value, xtd::size start_index)
Returns a single-precision floating point number converted from eight bytes at a specified position i...
static xtd::array< xtd::byte > get_bytes(char16 value) noexcept
Returns the specified xtd::char16 value as an xtd::array of bytes.
static xtd::array< xtd::byte > get_bytes(bool value) noexcept
Returns the specified Boolean value as an xtd::array of bytes.
Contains core_export_ keyword.
Contains enum_ and enum_ut_ keywords.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.hpp:27
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
std::vector< std::pair< enum_t, xtd::string > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition enum_collection.hpp:24
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr read_only_span(const element_type(&array)[len]) noexcept
Creates an xtd::read_only_span with specified native array.
Definition read_only_span.hpp:112
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
Contains xtd::read_only_span class.
Contains xtd::static_object class.
Provides the registration struct for enumerations.
Definition enum_register.hpp:38
Contains xtd fundamental types.