ndigit
Ndigit is a mathematical function that returns the number of digits required to represent a nonnegative integer n in a given base b (the radix). The base-10 case is the usual decimal digit count, but the concept generalizes to any base b ≥ 2. Formally, for n ≥ 0, ndigit_b(n) = floor(log_b(n)) + 1, with the convention ndigit_b(0) = 1. Equivalently, ndigit_b(n) = floor( ln(n) / ln(b) ) + 1 for n > 0.
Examples: ndigit_10(0) = 1, ndigit_10(7) = 1, ndigit_10(42) = 2. In base 2, ndigit_2(5) = 3 because 5 is 101
Generalization and conventions: negative integers can be handled by applying the function to their absolute value,
Computational aspects: in programming, ndigit_b(n) can be computed with logarithms or by repeated division by b.
Applications: digit counting is used in numeric formatting, data encoding, indexing, and algorithms that depend on