- integer-length iprocedure
The number of bits needed to represent i, i.e.
(ceiling (/ (log (if (negative? integer) (- integer) (+ 1 integer))) (log 2)))
The result is always non-negative.
For non-negative i, this is the number of bits needed to represent i in an unsigned binary representation. For all i, (+ 1 (integer-length i)) is the number of bits needed to represent i in a signed twos-complement representation.
(integer-length 0) => 0 (integer-length 1) => 1 (integer-length -1) => 0 (integer-length 7) => 3 (integer-length -7) => 3 (integer-length 8) => 4 (integer-length -8) => 3