I am wondering how you can represent an integer as a chain of 8-bit numbers.
That is, (and I don't know how to actually calculate this so the example is wrong, but should demonstrate the basic idea), say you have an integer of arbitrary size, meaning it can be extremely large like Math.pow(100, 100) ≈ 1e+200
or some small number like 1
or 0
. You want to be able to compute that number by using a chain of 8-bit values. The question is how to do that.
For example, I can represent 255
like this:
[ 255, 1 ]
That is, our representation has the first value be 8-bits, and then the second value is also 8-bits, and we multiply them together as 255 * 1 = 255
. Another case would be 256
. We could represent that like this:
[ 255, 1, 1 ]
Meaning (255 * 1) + 1 = 256
, but now we don't necessarily know what to add vs. what to multiply. Imagine a large number like 1589158915
. I have no idea what it's array of values would be, but say they ended up being like this:
[ 15, 12, 1, 141, 12, 250 ]
And say that from those numbers we could compute the value like this:
15 * 12 + 1 * 141 / 12 - 250
That wouldn't be very ideal, unless perhaps the system also stored the operation with the value, like this:
[ 15, 2, 12, 0, 1, 2, 141, 3, 12, 1, 250 ]
But I have no idea where to begin to figure out how to calculate the number like this, or how to say "given some integer, figure out how to break it apart into some equation that will generate its value". That is the basis of the question. I guess (actually) this would probably be the best approach.
As a sidenote, you can't take the integer 1589158915
and just represent it like this:
[ 1589158914, 1 ] == (1589158914 + 1)
because 1589158915
is not an 8-bit value. This is why it's tricky. In addition, we don't want to do it like this:
[ 255, 255, 255, 255, ... ]
==
255 + 255 + 255 + 255 + ...
Because that would be very inefficient. The solution should be a compact representation.
So the question is, how to take an integer and create an equation from it that will generate its value, where each component of the equation can be represented as an 8-bit integer.