When when we use base 2, binary, to count each bit has a different positive value(except the sign bit) for example:
0 0 0 0 0 0 0
64 32 16 8 4 2 1
Now I need to count in the range -120 - 120
using signed powers of 3, my "bits" are:
0 0 0 0 0 0 0 0 0 0
-81 -27 -9 -3 -1 1 3 9 27 81
How should I go about finding a method to actually count using these bits aside from memoizing what combination leads to which value at the start of the program?
In more mathematical terms, given a number n
how should I go about finding the combination of "powers of 3 bits" that is equal to n
.
As an alternative way to solve the problem, instead of a straight conversion between these numbering formats, it might be possible that given n
already converted into this "powers of 3" format, I can find n+1
in this format directly(without converting back to decimal, adding 1 and then converting back). However I also have no clue how to proceed in this direction.
I am constrained to this method of representing numbers since the main project is at its core, a fancier file converter and this is the format one of the file types i need to support uses.
P.S. If this is the wrong forum for this please direct me to the correct one. I'm not sure myself where exactly this kind of question should be asked.
EDIT: The representation of 0
is no bits set, all 0
s I believe, and whenever one of the bits gets set, its value is added to the number.