oct
oct(n, [pad])
Convert an integer to an octal string, optionally specifying a number of digits to pad to.
Examples
In the Julia programming language, the function oct(n, [pad])
is used to convert an integer n
to its octal representation as a string. Optionally, you can specify the number of digits to pad the resulting octal string.
-
Convert an integer to an octal string:
julia> oct(10) "12" julia> oct(15) "17"
The
oct
function converts the integern
to its octal representation as a string. -
Specify the number of digits to pad:
julia> oct(10, 4) "0012" julia> oct(15, 6) "000017"
By specifying the
pad
argument, the resulting octal string is padded with leading zeros to match the specified number of digits.
Common mistake example:
julia> oct(-10)
ERROR: DomainError with -10:
-10 is not a non-negative integer.
In this example, the oct
function expects a non-negative integer as the argument. Providing a negative integer will result in a DomainError
. Ensure that the input is a non-negative integer when using the oct
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.