unsigned
unsigned(x) > Unsigned
Convert a number to an unsigned integer. If the argument is signed, it is reinterpreted as unsigned without checking for negative values.
Examples
Here are some examples of how to use the unsigned
function in Julia:

Convert a signed integer to an unsigned integer:
julia> signed_int = 10; julia> unsigned_int = unsigned(signed_int) 18446744073709551606
This example converts the signed integer
10
to an unsigned integer using theunsigned
function. 
Convert a float to an unsigned integer:
julia> float_num = 3.14; julia> unsigned_int = unsigned(float_num) 3.14
The
unsigned
function can also be used to convert a floatingpoint number to an unsigned integer. However, the result will be the same as the original float sinceunsigned
does not perform any type conversion for nonintegers.  Convert a negative signed integer to an unsigned integer:
julia> negative_int = 100; julia> unsigned_int = unsigned(negative_int) 18446744073709551516
The
unsigned
function reinterprets the negative signed integer100
as an unsigned integer without checking for negative values. The resulting unsigned integer may not be the same as the original signed value.
Common mistake example:
julia> unsigned("10")
ERROR: MethodError: no method matching unsigned(::String)
In this example, the unsigned
function cannot convert a string to an unsigned integer. It is important to ensure that the argument passed to unsigned
is a numerical value that can be converted to an unsigned integer.
See Also
base, big, bytes2hex, cconvert, complex, convert, dec, hex, hex2bytes, hex2num, oct, oftype, parse, promote, signed, unsafe_convert, unsigned, widen,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.