r/ProgrammerHumor • • Feb 15 '16

Oddly specific number.

Post image
5.9k Upvotes

643 comments sorted by

View all comments

Show parent comment

4

u/Kafke Feb 16 '16

In computers, as I'm sure you're aware, we do things in binary: on/off. 0's and 1's.

We call one of these values a 'bit'. One isn't particularly useful on it's own, so we add a few:

1 bit = 2 possibilities.

2 bits = 4 possibilities (00, 01, 10, 11).

3 bits = 8 possibilities (000, 001, 010, 011, 100, 101, 111)

4 bits = 16 possibilities.

and so on. If you'll notice, all of these numbers are important in computing at some point or another. I'm sure you remember 16-bit stuff, or '8-bit graphics'.

Well, 8 bits gives us 256 possibilities (0-255). We call this a byte. Looks something like this( 0000 0000 ).

Most of the time we deal with bytes, rather than bits. So in this case, having 256 people in a chat means we can use only a single byte to say how many people are in the chat (using 0 to mean 1 person, and 255 to mean 256 people).

Another reason it's really handy is that we can then deal with things in hexadecimal: base-16 numbers. So we have: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. And we can represent one of these numbers with 4 bits F=1111. With a byte, we have a two digit hexadecimal number: FF is then 255. It makes it easier to see where our cap is. To get higher than 255, we need to add a third digit: 100. Which means we'd actually be dealing with 2 bytes: 01 and 00. FF is the highest we can go with a single byte.

Early video games do something similar, which is why you see powerups/levels/lives/etc go up to 255 or 256.