Thread:Pixel-Voxel/@comment-22439-20131107184806/@comment-9531161-20131113183917

Well, think about the fact that numbers can be represented by adding a certain amount of powers of 10. For instance, the number 8392 can be represented by:

2 X 1 9 X 10 3 X 100 8 X 1000

Notice how each digit on the left can just be 0-9, and that each number on the right is a power of 10 (10^0, 10^1, 10^2, 10^3). If you want, you can split the number up like this, store only the values you see on the left, and be done with it. In order to build the number up again, you read in the values, multiply by the appropriate power of 10 (which you don't need to store because they're in order), and add them all together. However, there's a more efficient way. Remember that each cell in the GRP can store the values 0-255. This means that you can break up the number into values from 0-255 times powers of 256. Because Petit Computer can only store values up to ~524000, we only need to store at most 3 cells, or enough to store a number up to (but not including) 256^3. Let's take an example like 36. This can just be represented by: 36 * 1    (256^0) 0  * 256   (256^1) 0  * 65536 (256^2)

So we'd just store the values 36, 0, and 0. We could then reconstruct it in just the same way that we did before. Let's take the example 257:

1 * 1     (256^0) 1 * 256    (256^1) 0 * 65536  (256^2)

In this case, we'd store 1, 1, and 0. That second 1 really means "1 * 256" remember, which is how we get 257. Assuming the number we want to store is called "VAL", the algorithm for this is then:

FOR I=0 TO 2 GPSET I,0,FLOOR(VAL/POW(256,I))%256 NEXT

Then to build it back up:

VAL=0 FOR I=0 TO 2 VAL=VAL+POW(256,I)*GSPOIT(I,0) NEXT

Some unnecessary math is performed here, but that's OK. I'd rather have simplicity over efficiency when learning. Of course, you'd need to change the offset for GPSET depending on where in the GRP you want to store it, but the idea of storing the numbers next to each other should still be in place.