ndigits

ndigits(n, b)

Compute the number of digits in number n written in base b.

Examples

  1. Count the number of digits in a decimal number:

    julia> ndigits(12345)
    5

    This example calculates the number of digits in the decimal number 12345.

  2. Count the number of digits in a binary number:

    julia> ndigits(0b101010, 2)
    6

    It computes the number of digits in the binary number 0b101010 (42 in decimal).

  3. Count the number of digits in a hexadecimal number:
    julia> ndigits(0x1A4B, 16)
    4

    This example determines the number of digits in the hexadecimal number 0x1A4B (6731 in decimal).

Common mistake example:

julia> ndigits(-123)
ERROR: ArgumentError: Base must be positive

Here, a negative number is provided as the argument for n, but the ndigits function expects a positive number. Ensure that the input value is valid and positive to avoid this error.

See Also

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: