Introduction: Why Different Bases?

In our previous lesson, we looked at how advanced gates like NAND and XOR process signals. However, logic gates only understand two things: On or Off. In the world of circuits, we represent these as 1 and 0.

While you and I count using ten digits (0 through 9), a circuit only has two. This is the difference between Base 10 (the Decimal system) and Base 2 (the Binary system). A Base simply tells us how many different symbols or digits are available in a counting system. To build meaningful programs and circuits, we need a way to translate our human numbers into this two-digit language that machines speak.

Recall: The Logic Of Place Value

Before we learn a new system, let's look at how you already count in Base 10. When you see the number 123, you know the 3 is in the ones place, the 2 is in the tens place, and the 1 is in the hundreds place. Each position is a power of 10.

Binary works exactly the same way, but instead of powers of 10, we use powers of 2. Each place or bit in a binary number has a specific value:

  • The first place (on the right) is worth 1.
  • The second place is worth 2.
  • The third place is worth 4.
  • The fourth place is worth 8.

Every time you move one spot to the left, the value doubles. By placing a 1 or a in these spots, we can represent any number using only two symbols.

The Division Method: Decimal To Binary

To convert a standard decimal number into binary, we use a process called repetitive division. This is the most reliable way to find the correct string of 1s and 0s.

To do this, you divide your number by 2 and keep track of the remainder (what is left over). You keep dividing the result until you reach zero. Let's try converting the number 13 into binary:

DivisionQuotient (Result)Remainder
13 / 261
6 / 230
3 / 211
1 / 201

To get the final binary number, you read the remainders from the bottom to the top.

  • In this example, reading from the bottom up gives us 1101.
  • A remainder of 1 means the value was odd, and a remainder of 0 means it was even.
  • This method works because each division moves us to the next "place value" in the binary system.
The Weight Method: Binary To Decimal

Once you have a binary number, you need to know how to read it back into a decimal number. We do this by looking at the weight of each position where a 1 appears.

Let’s look at the binary string 1010. To decode this, we assign the values we recalled earlier to each digit, starting from the right:

  • The first digit (right) is 0. Its weight is 1. (0 x 1 = 0)
  • The second digit is 1. Its weight is 2. (1 x 2 = 2)
  • The third digit is 0. Its weight is 4. (0 x 4 = 0)
  • The fourth digit is 1. Its weight is 8. (1 x 8 = 8)

Now, we simply add the values where a 1 was present: 8 + 2 = 10. By using these weights, you can quickly see that 1010 is just the machine's way of saying .

Shorthand for Circuits: Hexadecimal (Base 16)

As circuits get more complex, binary strings can become very long and difficult for humans to read. To make this easier, engineers use Hexadecimal (Base 16).

While Decimal uses 10 symbols and Binary uses 2, Hexadecimal uses 16. To get those extra symbols, we use the first six letters of the alphabet:

  • 0-9 represent their usual values.
  • A=10, B=11, C=12, D=13, E=14, F=15.
Converting Decimal to Hexadecimal

To convert a decimal number to Hex, we use the same repetitive division method we used for binary, but we divide by 16 instead of 2. Let's convert the number 188 into Hexadecimal:

DivisionQuotientRemainderHex Digit
188 / 161112C
11 / 16011B

Reading the remainders from the bottom to the top, we get BC.

The Binary Connection

The reason engineers specifically use Base 16 is because it fits perfectly with binary. Exactly four binary bits (often called a "nibble") can be represented by one hex digit.

  • Binary 1111 is 15, which is F in Hex.
  • Binary 0000 is 0, which is 0 in Hex.

Instead of writing out a long 8-bit string like 10111100, you can simply group the bits into two sets of four (1011 and 1100) and write it as BC. This shorthand doesn't change the logic of the circuit, but it makes the data much easier to manage when designing large systems.

Summary And Practice Readiness

In this lesson, we bridged the gap between how we count and how circuits "think." We covered:

  • How to use repetitive division to turn decimal numbers into binary strings by tracking remainders.
  • How to use weights (1, 2, 4, 8...) to convert binary back into decimal.
  • How to convert decimal to Hexadecimal by dividing and using symbols AF.
  • The connection between bases: how one Hex digit serves as shorthand for a group of four binary bits.

You are now ready to head into the Codesignal Logic Simulator. In the upcoming practice exercises, you will be asked to manually convert numbers to set the states of various logic circuits. Remember to keep a piece of paper nearby for your divisions, and always read your remainders from the bottom up!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal