It’s been awhile since my last post so I thought I’d go over something fun. We’re going to go over how to count to 1023 by hand using the binary system!

Decimal, or Base 10 System

First, let’s go over the common number system we use in our day-to-day lives: the base-10 system.

Let’s study the number 1023 considering we’ll be counting to it later. The base this number is based on is 10 and we can break it down further to make this more apparent. Let’s replace all the digits in the number like so: abcd and break down what this number actually means.

1023
----
abcd

a: 10^3 = 1000 * 1
b: 10^2 = 100  * 0
c: 10^1 = 10   * 2
d: 10^0 = 1    * 3
--------------------
a + b + c + d = 1023

The 10 that you see in the lefthand side after the colon is our current base. We figure out what that place stands for by the positioning it has and use that numbered place as a exponent, then we multiply by the number that is there. Note that for a given digit, a number from 0-9 can be used and that’s it. We then add all the products up and get the number it stands for. This might seem unproductive but the teardown should serve as a reminder of how the common decimal system works and will help as a scaffold to learning binary and any other base number system!

Binary, or Base-2, System

Now, let’s look at a binary representation of 1023:

0b1111111111

The “0b” stands as a preamble to tell the reader the number they’re about to read is a binary number (Side note: “0d” is what you can use to show a base-10 number). It’s optional for the most part but helps to be explicit to the reader otherwise they may read the 1’s as a base-10 number. Another way to represent the binary number is to break it into groups of 4 digits and pad the left with 0’s, this makes it easier for a human reader to calculate it. I’ve added letters at the bottom to help calculate as well.

0011 1111 1111
---- ---- ----
abcd efgh ijkl

a: 2^11 = 2048 * 0 = 0
b: 2^10 = 1024 * 0 = 0
c: 2^9  = 512  * 1 = 512
d: 2^8  = 256  * 1 = 256
e: 2^7  = 128  * 1 = 128
f: 2^6  = 64   * 1 = 64
g: 2^5  = 32   * 1 = 32
h: 2^4  = 16   * 1 = 16
i: 2^3  = 8    * 1 = 8
j: 2^2  = 4    * 1 = 4
k: 2^1  = 2    * 1 = 2
l: 2^0  = 1    * 1 = 1
------------------
a + b + ... + k + l = 1023

We simply replaced the “10” base with “2” instead. You can see that a certain digit can only be either a 1 or a 0 now instead of 0-9. The digit can also be used as a switch that decides whether we add the given weight or not (0 = don’t add, 1 = add)

We then sum up all the weights and get our number: 1023 By the way, a shortcut to calculating this: Since we have all the 1’s in a row we can look at the first 0 before the left-most 1, determine it’s weight (b is 1024 in this case) and simply subtract 1 from it to get the overall value. Likewise, adding 1 to the binary 1023 will make all the current 1 digits switch to 0 and then switch b’s place to a 1 to represent 1024.

Counting binary by hand

Now, let’s apply what we learned to counting by hand. In base-10, we tend to use each finger (or digit if you will) on our hand to have a weight of 1 only, which is inefficent since we can only count from 0-10. We tend to keep track of where we’re at in our head and recycle use of our fingers to continue adding by 1. I’m sure there are other more efficient finger counting processes but I won’t go over them.

Hold your hands palms up towards you. Let’s map each finger to a digit in binary:

0011 1111 1111
---- ---- ----
abcd efgh ijkl

a: 2^11 = 2048 (no finger here)
b: 2^10 = 1024 (no finger here)
c: 2^9  = 512  (left hand thumb) 
d: 2^8  = 256  (left hand index) 
e: 2^7  = 128  (left hand middle) 
f: 2^6  = 64   (left hand ring) 
g: 2^5  = 32   (left hand pinky)
h: 2^4  = 16   (right hand pinky) 
i: 2^3  = 8    (right hand ring) 
j: 2^2  = 4    (right hand middle) 
k: 2^1  = 2    (right hand index) 
l: 2^0  = 1    (right hand thumb) 

Now I’ll show you how progression of counting with your fingers work. You simply count up from the right to left. When you see a 1, you hold that finger up to represent that it’s “on”. A finger that’s down is “off” and is a 0. I’ll show the base-10 value as well via 0d delimiter to assist.

00 0000 0000 = 0d0
-- ---- ----
cd efgh ijkl

00 0000 0001 = 0d1
-- ---- ----
cd efgh ijkl

00 0000 0010 = 0d2
-- ---- ----
cd efgh ijkl

00 0000 0011 = 0d3
-- ---- ----
cd efgh ijkl

00 0000 0100 = 0d4
-- ---- ----
cd efgh ijkl

.
.
.
(let's jump to 0d16 which is your left hand pinky)

00 0001 0000 = 0d16
-- ---- ----
cd efgh ijkl

00 0001 0001 = 0d17
-- ---- ----
cd efgh ijkl

00 0001 0010 = 0d18
-- ---- ----
cd efgh ijkl

.
.
.
(finally jump to 0d1020 which is everything but right thumb and index)

11 1111 1100 = 0d1020
-- ---- ----
cd efgh ijkl

11 1111 1101 = 0d1021
-- ---- ----
cd efgh ijkl

11 1111 1110 = 0d1022
-- ---- ----
cd efgh ijkl

11 1111 1111 = 0d1023
-- ---- ----
cd efgh ijkl


c: 2^9  = 512  (left hand thumb) 
d: 2^8  = 256  (left hand index) 
e: 2^7  = 128  (left hand middle) 
f: 2^6  = 64   (left hand ring) 
g: 2^5  = 32   (left hand pinky)
h: 2^4  = 16   (right hand pinky) 
i: 2^3  = 8    (right hand ring) 
j: 2^2  = 4    (right hand middle) 
k: 2^1  = 2    (right hand index) 
l: 2^0  = 1    (right hand thumb) 

What’s nice about this system of counting is you don’t have to cache any number in your head. As long as you don’t move your fingers they can serve as a snapshot to where you’re at in your counting.

The most you can count to in binary

To figure out the max value you can count to with a given number of binary digits, use this simple formula:

(a^n)-1

Where a is 2 for the binary system and n is the number of binary digits you can work with. So, since a typical human has 10 fingers the formula yields: (2^10)-1 = (1024)-1 = 1023

For decimal, a is 10 and n is however many digits you’re working with.

Other Bases

You can create a base system with any number. Another popular one for programmers is hexadecimal, delimited with “0x”. The base for it is 16 It’s useful for programmers because one hexadecimal digit can hold four binary digit’s worth of value. It does this by counting not just from 0-9 but adds abcdef as values as well where a represents 10, and f is 15. Here are some example hexadecimal values where we show the hex representation, binary, then decimal.

0xbc
0b1011 1100
0d188 = (128 + 0 + 32 + 16) + (8 + 4 + 0 + 0)
-----------
0x9f
0b1001 1111
0d159 = (128 + 0 + 0 + 16) + (8 + 4 + 2 + 1)

For the decimal representation, I broke down each binary digit’s value to show how I came up with the calculation. Also, you can see how each digit in hexadecimal maps to a cluster of 4 binary digits (for 0xbc, b = 0b1011 and c = 0b1100)

Another fun tid bit: In binary, if the first digit (right most) is a 1 then it’s odd! Otherwise a 0 denotes an even number. How convenient :D

Congrats, now you can count like a computer. Happy counting!