Why 255 ?

  • 6 Replies
  • 3040 Views
*

Offline Polana

  • 396
  • 65
  • LOCP and proud
    • View Profile
Why 255 ?
« on: June 25, 2012, 22:36:37 »
Hi,
I always wonder, why there 255 tilesets, 255 gradients, 255 banks of objects, etc. in the editor. Why not 250 or 300 or some other "round" number ? Is it something in the program ?

*

Offline LPChip

  • You can only truly help other people by allowing them to fail.
  • 3510
  • 138
  • Excel at the thing you're the best at!
    • View Profile
    • LPChip Interactive
Re: Why 255 ?
« Reply #1 on: June 25, 2012, 23:39:34 »
there are 256, because it goes from 0 to 255.

256 is a value that in the computer world is called a byte. You have a value that has 256 unique possibilities, so you can use one byte per item to keep it the most simple. Otherwise, you have to combine 2 bytes and that involves math. True, also more possibilities, but also a bigger file.

Also: http://256.com/256.html
on the left, above my avatar.

MODPlug Central Forum
"If I tried to kill you, I'd end up with a big fat hole through my laptop." - Chironex

*

Offline Threrra

  • 10
  • 1
  • I make games too
    • View Profile
Re: Why 255 ?
« Reply #2 on: June 25, 2012, 23:46:40 »
Actually, it's 256 distinct numbers because "0" is a number, too.
A computer uses binary digits, 1 and 0. If you have 1 byte = 8 bits, your smallest binary number is 0000 0000, and your biggest number is 1111 1111 (=>2^8-1, or  255 in decimal systems).
So the index system in the editor uses a single byte to store indices.

300 in decimal becomes 1 0010 1100 in binary. It would have  9 bits instead of 8, but you can't just take single additional bits from your memory, because your memory is organized in bytes. You would need two bytes to handle a number as big as 300.
Then again with two bytes, you would have 65536(=2^16) different numbers. Altough you could force your program to reject numbers that are bigger than 300, there would be no logical reason to restrict it to 300

And 250 becomes 1111 1010. My computer doesn't think it's a "round" number  :^^:

Edit:LPChip beat me to it :(

*

Offline Raicuparta

  • 519
  • 41
  • Rai
    • View Profile
Re: Why 255 ?
« Reply #3 on: June 26, 2012, 13:38:29 »
If you look closely you will find this kind of limitation in many other games, like the 255 rupee limit in The Legend of Zelda. 8-bit videogames are a great example because they often struggled with memory problems.

*

Offline Polana

  • 396
  • 65
  • LOCP and proud
    • View Profile
Re: Why 255 ?
« Reply #4 on: June 26, 2012, 19:17:22 »
Thank you.
How could I forgot about zero! With 256 it makes perfect sense. I should think more before I ask about something.

Re: Why 255 ?
« Reply #5 on: October 20, 2012, 21:23:39 »
Actually, it reminds me quite a lot of 256 colours. Even though it seems a bit off-topic, they both seem very similar.

*

Offline Yoeri

  • 256
  • 15
  • Normality is relative
    • View Profile
    • Bumper's business
Re: Why 255 ?
« Reply #6 on: October 20, 2012, 22:17:27 »
Actually, it reminds me quite a lot of 256 colours. Even though it seems a bit off-topic, they both seem very similar.
It is. 256 (and 255, for that matter) is a very common number in computing, for the exact reason LPChip mentioned.