signed

signed(x)

Convert a number to a signed integer. If the argument is unsigned, it is reinterpreted as signed without checking for overflow.

Examples

Convert a number to a signed integer:

julia> signed(5)
5

julia> signed(-10)
-10

This function takes a number as input and converts it to a signed integer. If the argument is already signed, it is returned as is. If the argument is unsigned, it is reinterpreted as signed without checking for overflow.

Example:

julia> x = UInt8(200)
200

julia> signed(x)
-56

In this example, the unsigned integer 200 is reinterpreted as a signed integer, resulting in -56.

Common mistake example:

julia> y = 2.5
2.5

julia> signed(y)
ERROR: MethodError: no method matching signed(::Float64)

The signed function can only be used on numeric types. If you try to use it on a non-numeric type, such as a Float64, it will result in a MethodError. Make sure to provide a valid numeric argument to the signed function.

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.

*Required Field
Details

Checking you are not a robot: