The 256th Rupee

The original Legend of Zelda for the Nintendo Entertainment System is a classic. It was one of the first games my family owned and I spent countless hours exploring its massive world, discovering its secrets, and saving the mystical land of Hyrule. It was an amazing experience that, despite its simple graphics and animation, managed to engross me into its fantasy world.


That rupee ain't going to do you much good.

Well, most of the time. There was one thing that irritated me and, while a silly thing to notice, it was like an unsanded edge that reminded me that I was playing a very rudimentary game that had definite limits: I couldn't collect more than 255 rupees. Why? It isn't because there isn't space on the screen, as then the limit would be 999 or 99. This baffled me as a child. Who sets these limits? Why 255? It seemed so arbitrary.

Well, limits like this exist because of how numbers and data are stored and handled by computers. And video game consoles, despite their more limited purpose, are just simple computers. Rudamentary, yes. However, they still use CPUs to run code and do simple math, they still use memory chips, and they still can only store data as numbers.

Now you've probably already heard lecturing about how everything inside a computer is made up of ones and zeroes, but it's a description so vague as to be almost useless. What does that really mean?

Let's step down a level. If you open up a computer (or in this case, a Nintendo) you'll see a few chips attached to circuit board with some copper lines running all over the place between the different pieces. In a basic description, all these chips can do is put a voltage to these different copper connections or put none at all. The chip on the other side of that copper line can then read to see if there is a voltage or not. They use this ability to communicate with each other. They can use this method to send data to each other in a way similar to morse code. Except instead of long and short beeps, you have high and low voltages. So the CPU can send and receive data to and from the memory, for example, using this simple system of high and low voltages. Or data to and from the controller. Even internally, the chips can only store data or do logic based on whether there is a high or low voltage.


A Super Nintendo Autopsy

Now, step back up a level. It's great that all these pieces can now communicate with each other and do logic with this data, but what good is that on its own? Well, since that's the only type of way for computers to understand things, through voltages being either ON or OFF, we're going to have to build a way to keep track of numbers using just that.

To start things off, let's have OFF and ON represented by 0 and 1 respectively. Those are at least numbers now, though there aren't too many things where only being able to count up to 1 is useful. You can keep track of whether there is 1 of something or not. ...can we do anything more? Well, take a quick look at our own numbering system. Our system only goes from 0 to 9. Yet we can count higher than 9 by simply adding more digit positions, with each extra digit being a power of 10. So we don't get stuck at 9, we can count up to ten by adding another digit to left. 10. This system we use every day is called 'decimal' (which comes from the same latin root of the word 'ten'). Why not just do the same with 0's and 1's? Let's do just that.


Counting up in binary - with equivalent decimal values

Think of an odometer on a car. As the car drives, the digit on the far right slowly increases. It starts at 0, moves up through 1, 2, and so on until it hits 9. When the farthest digit rolls over 9 back to 0, the next digit increases. If the next digit is 9, it rolls over to 0 and the next digit over increases. And so on and so on. Instead, for computers we only have 0 and 1. However, that doesn't stop us from reaching higher numbers. If 0 increases, it goes to 1. If 1 increases, it goes back to 0 and increases the next digit. If the next digit is also 1, that digit also goes to 0 and the next digit to the left is increased. Etc. etc. It's actually a relatively simple concept if you see it. 0 becomes 1. 1 becomes 10. 10 becomes 11. 11 becomes 100. 100 becomes 101. It increases just like our regular numbers do.

So at the basic level, computers use a bunch of ON and OFF states to represent different numbers in the way just described. This system of 0's and 1's is known as binary and is the fundamental system of mathematics in computing, and has its own basic arithmetic operations. It's efficient, and works well. That being said, we humans aren't so used to it. It'd be really, really awkward for us to try to figure out if we have enough rupees to buy that blue ring when we have 1100010 rupees in binary. So instead, when being shown to us on the screen it is converted to decimal to make it easy for us. The actual DATA however, is stored in binary.

Now, what does all this have to do with keeping track of how many coins we have collected? On the screen, there's only space for 3 digits. In decimal, that would have a maximum of 999. However, we aren't using decimal digits underneath it all. We're using binary, and it has maximum values for different numbers of digits as well, but they don't coincide exactly with the ones in decimal. In that 10 digit system, if you have 4 digits, you can represent 10000 different values: 0 to 9999. In binary if you have 4 digits you can only represent 16 values: 0000 to 1111, which converts to 0 to 15. These binary digits are known in computing circles as 'bits' - so a number of four digits would be a 4-bit number.

A maximum number in binary is simply all 1s in all the positions. For reference, here is a list of some maximum numbers in binary:

1 = 1
11 = 3
111 = 7
1111 = 15
11111 = 31
111111 = 63
1111111 = 127
11111111 = 128
111111111 = 255
1111111111 = 511
11111111111 = 1023
...so on and so on...

And looking in that list, we can see that for 8 binary digits we have a maximum of 255. Tada! So the reason you can't collect more than 255 rupees is because inside the NES, in the code that is running the game, they use 8 binary digits to keep track of how many you have. It's from maximum numbers like this why many games, especially early ones, had some very odd limits. Zelda limited you to 255 rupees, Dragon Warrior limited you to 65535 experience points, Rygar had limits of 4095 points. These limits are the maximum value of the number of 1's that could be held in the size of the binary number they chose to use to store the data.

'Wait!' you may say. 'Why not just use more digits so that the maximum would be higher?' That's a good question that has two answers. The first answer is that the memory to store all those numbers was limited. While the code was running these numbers would have to be stored in memory (since the CPU itself couldn't hold them all), along with lots of other things, and they had to choose carefully what to put in there because memory was very expensive back then. In fact, the NES by default only had 2KB of RAM, meaning it could only store 2048 different 0's and 1's at a time (unless the cartridge had extra RAM chips in it). So in order to save space, they would only use as little as necessary.

The second answer may be for simplicity. You may know the old Nintendo was known as an '8-bit' system. As stated above, the word 'bit' is just short for 'binary digit' and at the time it meant the processor was built to handle numbers that held 8 binary digits. It could be used to handle numbers larger than that, but it required more programming (essentially it would have to treat it as two 8-bit numbers and do some extra math if necessary). The fundamental mathematical unit the NES was built to handle was just 8-bits. It could simply have not been worth the extra effort for the programmers to handle more a larger number in that case.

So that's it. Zelda limited you to 255 rupees because the 8 bits it stored the number in had a maximum of 255. So next time you're running around Hyrule and collecting triforces, remember that it's just a bunch of tiny voltages being interpreted as numbers.