Numeral Systems

Anna Romsa
The Startup
Published in
4 min readJul 29, 2020

Decimal, Binary, Octal, and Hexadecimal

A numeral system (or system of numeration) is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner. The number the numeral represents is called its value.

While studying JavaScript I became curious about numeral systems when using the parseInt( ) function. The parseInt( ) function is used to parse a string into an integer. This function accepts two arguments, the first argument is the string you want to parse, and the second argument is the radix.

The radix or base is the number of unique digits used to represent numbers in a positional numeral system. The radix in the parseInt( ) function can be any number 2–36 and does not default to base 10. Let’s explore a few of the counting systems that we use today.

Decimal System or Base 10

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Base 10 is the counting system that most of us are used to working with so we will start there. The radix/base number is 10 because it uses 10 digits. Let’s look at the number 974,210. In the example below the 0 is in the “one’s position”, the 1 is in the “ten’s position”, the 2 is in the “hundred’s position”, the 4 is in the “thousand’s position” and so on. Each number is worth ten times more than the digit to the right.

Fun fact: Many ancient civilizations used base 10 to represent numbers. It is rumored that this is due to humans starting to count using their 10 fingers.

Binary System or Base 2

Unique Digits = 0, 1

In binary there are only two digits to represent each number so each position is worth two times more than the position to its right.

If we were to count in binary, since we only have two digits to work with, we start with 0, then 1, then 10, 11, 100, 101 and so on. For example, here is binary compared to decimal:

Fun fact: The modern binary number system was studied in Europe in the 16th and 17th centuries however, systems related to binary numbers have appeared earlier in multiple cultures including ancient Egypt, China, and India.

Octal System or Base 8

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7

We have 8 unique digits to represent values in the octal system. When we get to 7 the next number will be 10, then 11 and so on. Once all of the symbols/digits have been used, we start at 0 again and increase the digit to the left by 1.

Fun fact: The Yuki people, native to California, use the octal system because they count using the spaces between their fingers.

Hexadecimal System or base 16

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

In hexadecimal, we have 16 digits (10 numbers and 6 letters) to represent the values. When we reach 9, next number is represented by the letter A, then B through F. After F comes 10 and so on.

Fun fact: Hexadecimal is often used to represent colors on web pages using the format #RRGGBB (RR = reds, GG = greens, BB = blues). The # (or octothorp) indicates that the number was written in hexadecimal. Each hexadecimal digit is also known as a nibble which represents four binary digits or half a byte.

Now that we have covered a few of the most commonly used numeral systems, let’s get back to parseInt( ). The majority of the time we want to default to base 10, particularly when using the parseInt( ) function so it’s safe to say that we can rely on setting the radix argument to base 10. Keep in mind that parseInt( ) does not default to base 10 so don’t forget to set your radix when using parseInt( ).

parseInt(myNumber, 10)

To get a better feel for the 4 counting systems that we discussed above, I am listing them side-by-side up to 100 in decimal.

--

--