I want to create my own range of numbers in Java, and still be able to use the normal ones. I just can’t seem to solve it! That is without hard coding every result.
Let’s say. Integers go like 0, 1, 2, 3, 4, 5, 6, 7, 8…. and so on (I know! there are also negative int’s)
Now, I’d like to make my own “numbers” that can be used both as integers and their own type.
A simple cut of the numbers range is 1, 2, 3, 5, 4, 7, 6, 9, 10, 11, 8, 13, 14, 15, 12, 17, 18, 19, 20, 21, 22, 23, 16… and so on… A sheet of the all numbers are shown below. (I don’t need any numbers above 767, but the next number is 512, then 769+ and so one.
1 2 3 5 4 7 6 9-11 8 13-15 12 17-23 16 25-31 24 33-47 32 49-63 48 65-95 64 97-127 96 129-191 128 193-255 192 257-383 256 385-511 384 513-767
Now lets call these numbers tni’s (opposite of int)
Let’s say I’d like to add (int)A to (tni)B This should be normal math. So if A = 4 and B = 6, the result will be 10, not 8.
But if I want to see which one of 2 tni’s are the highest. Let’s say A=8 and B=10, id will tell me that A is higher, as in the tni range, 8 comes after 10.
Is this possible?
The best way I see of doing this is to create an array denoting each ‘normal’ int’s position in the tni sequence.
For example:
Then, you can compare them with a method like this:
Yes, this is a fairly inelegant solution, but it seems like you have an inelegant problem in the first place.