I need to implement a custom integer arithmetic system, like Hexadecimal but with 4 more letters.
For example, Hexadecimal uses [0-9,A-F]
to represent a number. Mine will use [0-9,A-J]
.
Sample representations:
Decimal(5): Hex(5), MySystem(5)
Decimal(15): Hex(F), MySystem(F)
Decimal(16): Hex(10), MySystem(G)
Decimal(17): Hex(11), MySystem(H)
Decimal(18): Hex(12), MySystem(I)
Decimal(19): Hex(13), MySystem(J)
Decimal(20): Hex(14), MySystem(10)
...
I cannot decide if i should store numbers as String
or as BigInteger
.
It would really help if you could point me to somewhere where i could read how Hex is implemented in code. So far, i have only been able to find implementations only for conversions from/to other arithmetic systems.
That's just integers with a radix of 20 (base 20).
Remember the difference between the value (an abstract concept) and its representation. You care about representation only on input and output. When you input values they will be represented in base-20, and you want to output them in base-20. As long as that interface is satisfied, how the numbers are represented inside your code shouldn't matter, so you should use the most convenient representation for the range you need to cover (int, long or BigInteger).
Java already has all the necessary infrastructure to deal with this. Check out the Integer.parseInt(String value, int radix)
for input. For output there's Integer.toString(int value, int radix)