xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
bit_converter.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <vector>
7 
8 #include "core_export.h"
9 #include "static.h"
10 #include "types.h"
11 #include "ustring.h"
12 
14 namespace xtd {
50  public:
52 #if defined(__linux__) && defined(_LP64)
53  using llong = long long int;
54  using ullong = unsigned long long int;
55 #else
56  using llong = long;
57  using ullong = unsigned long;
58 #endif
60 
67  static const bool is_little_endian;
68 
76  static int64_t double_to_int64_bits(double value);
77 
84  static std::vector<byte_t> get_bytes(bool value);
85 
92  static std::vector<byte_t> get_bytes(char value);
93 
100  static std::vector<byte_t> get_bytes(char16_t value);
101 
108  static std::vector<byte_t> get_bytes(char32_t value);
109 
116  static std::vector<byte_t> get_bytes(wchar_t value);
117 
124  static std::vector<byte_t> get_bytes(double value);
125 
132  static std::vector<byte_t> get_bytes(int16_t value);
133 
140  static std::vector<byte_t> get_bytes(int32_t value);
141 
148  static std::vector<byte_t> get_bytes(int64_t value);
149 
156  static std::vector<byte_t> get_bytes(float value);
157 
164  static std::vector<byte_t> get_bytes(uint16_t value);
165 
172  static std::vector<byte_t> get_bytes(uint32_t value);
173 
180  static std::vector<byte_t> get_bytes(uint64_t value);
181 
183  static std::vector<byte_t> get_bytes(llong value);
184  static std::vector<byte_t> get_bytes(ullong value);
186 
191  static float int32_bits_to_single(int32_t value);
192 
197  static double int64_bits_to_double(int64_t value);
198 
203  static int32_t single_to_int32_bits(float value);
204 
214  static bool to_boolean(const std::vector<byte_t>& value, size_t start_index);
215 
224  static char32_t to_char(const std::vector<byte_t>& value, size_t start_index);
225 
234  static double to_double(const std::vector<byte_t>& value, size_t start_index);
235 
244  static int16_t to_int16(const std::vector<byte_t>& value, size_t start_index);
245 
254  static int32_t to_int32(const std::vector<byte_t>& value, size_t start_index);
255 
264  static int64_t to_int64(const std::vector<byte_t>& value, size_t start_index);
265 
274  static float to_single(const std::vector<byte_t>& value, size_t start_index);
275 
284  static uint16_t to_uint16(const std::vector<byte_t>& value, size_t start_index);
285 
294  static uint32_t to_uint32(const std::vector<byte_t>& value, size_t start_index);
295 
304  static uint64_t to_uint64(const std::vector<byte_t>& value, size_t start_index);
305 
314  static xtd::ustring to_string(const std::vector<byte_t>& value);
315 
326  static xtd::ustring to_string(const std::vector<byte_t>& value, size_t start_index);
327 
341  static xtd::ustring to_string(const std::vector<byte_t>& value, size_t start_index, size_t length);
342  };
343 }
344 
Converts base data types to an std::vector of bytes, and an std::vector of bytes to base data types.
Definition: bit_converter.h:49
static int16_t to_int16(const std::vector< byte_t > &value, size_t start_index)
Returns a 16-bit signed integer converted from two bytes at a specified position in a byte_t std::vec...
static std::vector< byte_t > get_bytes(bool value)
Returns the specified Boolean value as an std::vector of bytes.
static int32_t single_to_int32_bits(float value)
Converts the specified single-precision floating point number to a 32-bit signed integer.
static std::vector< byte_t > get_bytes(int64_t value)
Returns the specified int64_t value as an std::vector of bytes.
static xtd::ustring to_string(const std::vector< byte_t > &value)
Converts the numeric value of each element of a specified std::vector of bytes to its equivalent hexa...
static std::vector< byte_t > get_bytes(uint16_t value)
Returns the specified uint16_t value as an std::vector of bytes.
static std::vector< byte_t > get_bytes(uint32_t value)
Returns the specified uint32_t value as an std::vector of bytes.
static std::vector< byte_t > get_bytes(double value)
Returns the specified double value as an std::vector of bytes.
static int32_t to_int32(const std::vector< byte_t > &value, size_t start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a byte_t std::vec...
static xtd::ustring to_string(const std::vector< byte_t > &value, size_t start_index)
Converts the numeric value of each element of a specified sub std::vector of bytes to its equivalent ...
static char32_t to_char(const std::vector< byte_t > &value, size_t start_index)
Returns a char32_t converted from two bytes at a specified position in a byte_t std::vector.
static std::vector< byte_t > get_bytes(float value)
Returns the specified single value as an std::vector of bytes.
static uint64_t to_uint64(const std::vector< byte_t > &value, size_t start_index)
Returns a 64-bit unsigned integer converted from two bytes at a specified position in a byte_t std::v...
static int64_t to_int64(const std::vector< byte_t > &value, size_t start_index)
Returns a 64-bit signed integer converted from two bytes at a specified position in a byte_t std::vec...
static std::vector< byte_t > get_bytes(wchar_t value)
Returns the specified Char value as an std::vector of bytes.
static xtd::ustring to_string(const std::vector< byte_t > &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 float to_single(const std::vector< byte_t > &value, size_t start_index)
Returns a single-precision floating point number converted from eight bytes at a specified position i...
static std::vector< byte_t > get_bytes(int16_t value)
Returns the specified int16_t value as an std::vector of bytes.
static int64_t double_to_int64_bits(double value)
Converts the specified double-precision floating point number to a 64-bit signed integer.
static const bool is_little_endian
Indicates the byte_t order ("endianness") in which data is stored in this computer architecture.
Definition: bit_converter.h:67
static bool to_boolean(const std::vector< byte_t > &value, size_t start_index)
Returns a Boolean value converted from one byte_t at a specified position in a byte_t std::vector.
static std::vector< byte_t > get_bytes(int32_t value)
Returns the specified int32_t value as an std::vector of bytes.
static std::vector< byte_t > get_bytes(char16_t value)
Returns the specified Char value as an std::vector of bytes.
static std::vector< byte_t > get_bytes(char value)
Returns the specified Char value as an std::vector of bytes.
static double to_double(const std::vector< byte_t > &value, size_t start_index)
Returns a double-precision floating point number converted from eight bytes at a specified position i...
static std::vector< byte_t > get_bytes(char32_t value)
Returns the specified Char value as an std::vector of bytes.
static uint16_t to_uint16(const std::vector< byte_t > &value, size_t start_index)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte_t std::v...
static std::vector< byte_t > get_bytes(uint64_t value)
Returns the specified uint64_t value as an std::vector of bytes.
static float int32_bits_to_single(int32_t value)
Converts the specified 32-bit signed integer to a single-precision floating point number.
static double int64_bits_to_double(int64_t value)
Converts the specified 64-bit signed integer to a double-precision floating point number.
static uint32_t to_uint32(const std::vector< byte_t > &value, size_t start_index)
Returns a 32-bit signed integer converted from two bytes at a specified position in a byte_t std::vec...
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains core_export_ keyword.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition: static.h:38
#define core_export_
Define shared library export.
Definition: core_export.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::static_object class.
Contains xtd fundamental types.
Contains xtd::ustring class.