to_byte
September 14, 2025 ยท View on GitHub
Shows how to use xtd::convert::to_byte method.
Sources
Build and run
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:
xtdc run
Output
Convert int to byte :
---------------------
static_cast<byte>(value) = 42
as<byte>(value) = 42
convert::to_byte(value) = 42
Convert float to byte :
-----------------------
static_cast<byte>(float_value) = 42
as<byte>(float_value) = 43
convert::to_byte(float_value) = 43
Convert any to byte :
---------------------
any_cast<byte>(any_value) = 42
as<byte>(any_value) = 42
convert::to_byte(any_value) = 42
Convert string to byte :
------------------------
parse<byte>(string_value)) = 42
as<byte>(string_value) = 42
convert::to_byte(string_value) = 42
Convert hexa string to byte :
-----------------------------
parse<byte>(string_hex_value, number_styles::hex_number) = 42
as<byte>(string_hex_value, 16) = 42
convert::to_byte(string_hex_value, 16)) = 42
Convert int to byte with overflow :
-----------------------------------
static_cast<byte>(overflow_value) = 1
(ERROR) as : Overflow exception
(ERROR) convert::to_byte : Overflow exception