10 Types of People
1+1=10
As the old joke goes, “There are 10 types of people, those that understand how binary numbers work and those that don’t.” Let’s get you into the “understand” group.
Binary is the type of numbering system that is native to computers. It is base-2. Numbers that normal people work with are called decimal or base-10.
For normal base-10 numbers you use the digits 0 through 9 to describe a number. Here’s how you would count out 10 things:
1
2
3
4
5
6
7
8
9
And now you’ve run out out digits. So you put a “1” in the tens place and a “0” in the ones place to get:
10
To try counting the same quantity in binary your first realization should be that you only have two digits (base-2) to work with: 0 and 1. So the counting would look like this:
1
And now you’ve immediately run out of digits. So you put a “1” in the twos place and a “0” in the ones place and start counting again:
10
11
And you’ve run out of digits again. This happens a lot with binary, which is why it’s not a great numbering system for people. Just continue the pattern to keep counting:
100
101
110
111
1000
1001
1010
We’ll stop here since we have now counted up to “10” in decimal.
Another way you can parse this number is to think of how each position represents a component of the number.
With binary 1010 the components are as follows:
1 * 23 = 8
0 * 22 = 0
1 * 21 = 2
0 * 20 = 0
Adding 8 + 2 gets you to 10 decimal.
You’ve probably heard the term “8-bit” so what is an 8-bit number? Because bits are either 0 or 1 they are represented as binary. So an 8-bit binary number with all values set to one is this:
11111111
That is the largest number you can fit into 8 bits. And converted to decimal it is:
1 * 2^7 + 1 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 1 * 2^2 + 1 * 2^1 + 1 * 2^0
That breaks down to:
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
Which sums to 255, a number I’m sure you’ve seen around before: An 8-bit number is also called a Byte.
Here’s an Atari BASIC program that converts a binary value to decimal:
10 REM BINARY TO DECIMAL
20 DIM BIN1$(8),BIN2$(8)
30 PRINT "ENTER A BINARY NUMBER";:INPUT BIN1$
40 BIN2$="00000000"
50 BIN2$(9-LEN(BIN1$))=BIN1$
60 DECIMAL=0
70 FOR I=1 TO LEN(BIN2$)
80 PLC=VAL(BIN2$(I,I))*2^(8-I):PLC=INT(PLC+0.5)
90 DECIMAL=DECIMAL+PLC
100 NEXT I
110 PRINT "BINARY ";BIN2$;" IS ";INT(DECIMAL);" DECIMAL."
Conversely, you can convert a decimal number to binary by repeatedly dividing it by 2 and noting the remainder. When the remainder is even you write a 0, when it is odd you write a 1. And then you read the number from the bottom up.
So to convert decimal 10 to binary:
10 / 2 = 5, with a remainder of 0. 0 is even so write a “0”:
0
Now divide 5 / 2 to get 2 with a remainder of 1, which is odd:
0
1
Now divide 2 /2 to get 1, with a remainder of 0:
0
1
0
Lastly, divide 1 / 2 to get 0 with a remainder of 1 which is odd. So you end up with this:
0
1
0
1
Reading that from the bottom up gives you: 1010
Here’s an Atari BASIC program that converts a decimal number to binary:
10 REM DECIMAL TO BINARY
20 PRINT "ENTER A DECIMAL NUMBER";:INPUT DEC
25 DIM BIN$(8):BIN$="00000000":I=8:ORIGDEC=DEC
30 DIV=INT(DEC/2)
40 RMD=DEC-(DIV*2)
55 BINVAL=1
60 IF RMD/2=INT(RMD/2) THEN BINVAL=0
80 DEC=DIV
90 BIN$(I,I)=STR$(BINVAL)
95 I=I-1
100 IF DIV>0 THEN GOTO 30
110 PRINT ORIGDEC;" DECIMAL IS ";BIN$;" BINARY."
I hope you now consider yourself part of the group that understands binary!