xtd 0.2.0
Loading...
Searching...
No Matches
bit_converter.h
Go to the documentation of this file.
1
4#pragma once
5#include "core_export.h"
6#include "enum.h"
7#include "static.h"
8#include "types.h"
9#include <vector>
10
12namespace xtd {
52 private:
53 static constexpr uint32 __endian_value__ = 0x01020304;
54 static constexpr xtd::byte __endian_query__ = static_cast<const xtd::byte&>(__endian_value__);
55
56 public:
59 enum class endian {
61 little,
63 big,
64 };
65
67
75 static constexpr bool is_big_endian = __endian_query__ == 0x01u;
82 static constexpr bool is_little_endian = __endian_query__ == 0x04u;
89 static constexpr endian endianness = is_little_endian ? endian::little : endian::big;
91
93
102 static int64 double_to_int64_bits(double value) noexcept;
103
110 static std::vector<xtd::byte> get_bytes(bool value) noexcept;
111
118 static std::vector<xtd::byte> get_bytes(char value) noexcept;
119
126 static std::vector<xtd::byte> get_bytes(char16 value) noexcept;
127
134 static std::vector<xtd::byte> get_bytes(char32 value) noexcept;
135
142 static std::vector<xtd::byte> get_bytes(wchar value) noexcept;
143
150 static std::vector<xtd::byte> get_bytes(double value) noexcept;
151
155 static std::vector<xtd::byte> get_bytes(sbyte value) noexcept;
156
163 static std::vector<xtd::byte> get_bytes(int16 value) noexcept;
164
171 static std::vector<xtd::byte> get_bytes(int32 value) noexcept;
172
179 static std::vector<xtd::byte> get_bytes(int64 value) noexcept;
180
187 static std::vector<xtd::byte> get_bytes(float value) noexcept;
188
192 static std::vector<xtd::byte> get_bytes(xtd::byte value) noexcept;
193
200 static std::vector<xtd::byte> get_bytes(uint16 value) noexcept;
201
208 static std::vector<xtd::byte> get_bytes(uint32 value) noexcept;
209
216 static std::vector<xtd::byte> get_bytes(uint64 value) noexcept;
217
219 static std::vector<xtd::byte> get_bytes(slong value) noexcept;
220 static std::vector<xtd::byte> get_bytes(xtd::ulong value) noexcept;
222
227 static float int32_bits_to_single(int32 value) noexcept;
228
233 static double int64_bits_to_double(int64 value) noexcept;
234
239 static int32 single_to_int32_bits(float value) noexcept;
240
250 static bool to_boolean(const std::vector<xtd::byte>& value, size_t start_index);
251
260 static char32 to_char(const std::vector<xtd::byte>& value, size_t start_index);
261
270 static double to_double(const std::vector<xtd::byte>& value, size_t start_index);
271
280 static int16 to_int16(const std::vector<xtd::byte>& value, size_t start_index);
281
290 static int32 to_int32(const std::vector<xtd::byte>& value, size_t start_index);
291
300 static int64 to_int64(const std::vector<xtd::byte>& value, size_t start_index);
301
310 static float to_single(const std::vector<xtd::byte>& value, size_t start_index);
311
320 static uint16 to_uint16(const std::vector<xtd::byte>& value, size_t start_index);
321
330 static uint32 to_uint32(const std::vector<xtd::byte>& value, size_t start_index);
331
340 static uint64 to_uint64(const std::vector<xtd::byte>& value, size_t start_index);
341
350 static xtd::string to_string(const std::vector<xtd::byte>& value);
351
362 static xtd::string to_string(const std::vector<xtd::byte>& value, size_t start_index);
363
377 static xtd::string to_string(const std::vector<xtd::byte>& value, size_t start_index, size_t length);
379 };
380}
381
383template<> struct xtd::enum_register<xtd::bit_converter::endian> {
384 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"}};}
385};
Represents text as a sequence of character units.
Definition basic_string.h:79
Converts base data types to an std::vector of bytes, and an std::vector of bytes to base data types.
Definition bit_converter.h:51
static float int32_bits_to_single(int32 value) noexcept
Converts the specified 32-bit signed integer to a single-precision floating point number.
static int32 to_int32(const std::vector< xtd::byte > &value, size_t start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte std::...
static std::vector< xtd::byte > get_bytes(uint16 value) noexcept
Returns the specified uint16 value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(wchar value) noexcept
Returns the specified Char value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(int16 value) noexcept
Returns the specified int16 value as an std::vector of bytes.
static float to_single(const std::vector< xtd::byte > &value, size_t start_index)
Returns a single-precision floating point number converted from eight bytes at a specified position i...
static std::vector< xtd::byte > get_bytes(uint32 value) noexcept
Returns the specified uint32 value as an std::vector 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 int16 to_int16(const std::vector< xtd::byte > &value, size_t start_index)
Returns a 16-bit signed integer converted from two bytes at a specified position in a xtd::byte std::...
static uint16 to_uint16(const std::vector< xtd::byte > &value, size_t start_index)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a xtd::byte std...
static xtd::string to_string(const std::vector< xtd::byte > &value, size_t start_index)
Converts the numeric value of each element of a specified sub std::vector of bytes to its equivalent ...
static bool to_boolean(const std::vector< xtd::byte > &value, size_t start_index)
Returns a Boolean value converted from one xtd::byte at a specified position in a xtd::byte std::vect...
static std::vector< xtd::byte > get_bytes(char value) noexcept
Returns the specified Char value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(xtd::byte value) noexcept
Returns the specified xtd::byte value as an std::vector of bytes.
static xtd::string to_string(const std::vector< xtd::byte > &value)
Converts the numeric value of each element of a specified std::vector of bytes to its equivalent hexa...
static xtd::string to_string(const std::vector< xtd::byte > &value, size_t start_index, size_t length)
Converts the numeric value of each element of a specified sub std::vector of bytes to its equivalent ...
static std::vector< xtd::byte > get_bytes(sbyte value) noexcept
Returns the specified xtd::byte value as an std::vector of bytes.
endian
Represents the xtd::byte order ("endianness") in which data is stored in this computer architecture.
Definition bit_converter.h:59
@ little
Represnets "Little-endian" order.
@ big
Represnets "Big-endian" order.
static int32 single_to_int32_bits(float value) noexcept
Converts the specified single-precision floating point number to a 32-bit signed integer.
static uint64 to_uint64(const std::vector< xtd::byte > &value, size_t start_index)
Returns a 64-bit unsigned integer converted from two bytes at a specified position in a xtd::byte std...
static std::vector< xtd::byte > get_bytes(int32 value) noexcept
Returns the specified int32 value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(bool value) noexcept
Returns the specified Boolean value as an std::vector of bytes.
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 std::vector< xtd::byte > &value, size_t start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a xtd::byte std::...
static int64 to_int64(const std::vector< xtd::byte > &value, size_t start_index)
Returns a 64-bit signed integer converted from two bytes at a specified position in a xtd::byte std::...
static std::vector< xtd::byte > get_bytes(char16 value) noexcept
Returns the specified Char value as an std::vector of bytes.
static char32 to_char(const std::vector< xtd::byte > &value, size_t start_index)
Returns a char32 converted from two bytes at a specified position in a xtd::byte std::vector.
static std::vector< xtd::byte > get_bytes(double value) noexcept
Returns the specified double value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(char32 value) noexcept
Returns the specified Char value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(int64 value) noexcept
Returns the specified int64 value as an std::vector of bytes.
static std::vector< xtd::byte > get_bytes(uint64 value) noexcept
Returns the specified uint64 value as an std::vector of bytes.
static double to_double(const std::vector< xtd::byte > &value, size_t start_index)
Returns a double-precision floating point number converted from eight bytes at a specified position i...
static std::vector< xtd::byte > get_bytes(float value) noexcept
Returns the specified single value as an std::vector 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.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
int16_t int16
Represents a 16-bit signed integer.
Definition int16.h:23
wchar_t wchar
Represents a wide character.
Definition wchar.h:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.h:23
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.h:27
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.h:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.h:26
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.h:26
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.h:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.h:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.h:23
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.h:27
std::vector< xtd::collections::generic::key_value_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.h:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::static_object class.
Provides the registration struct for enumerations.
Definition enum_register.h:38
Contains xtd fundamental types.