The DigitCount[n,b]
function "counts the gives a list of the numbers of $1, 2, \ldots, b-1, 0$ digits in the base-$b$ representation of $n$".
I want to extend this to negative bases, for instance when $b=-2$. Is there already a function for this is Mathematica? Or perhaps a "quick" solution?
Question
How to extend DigitCount[n,b]
for negative b
?
Due diligence
Wikipedia's Negative base article provides code examples to calculate negative base representation in various languages, but no Wolfram Language.
BaseForm
, IntegerDigits
and IntegerLength
explicitly state in their error messages that the bases must be integers larger than $1$, so it seems that current versions of Mathematica do not have built-in implementations for negative basis.
BaseForm[42, -2]
BaseForm::intpm: Positive machine-sized integer expected at position 2 in
BaseForm[42, -2]
IntegerDigits[42, -2]
IntegerDigits::ibase: Base -2 is not an integer greater than 1.
IntegerLength[42, -2]
IntegerLength::ibase: Base -2 is not an integer greater than 1.