Ever wonder how your computer, which only "speaks" in zeros and ones, can understand the numbers we use every day? It all comes down to a fascinating process called number system conversion! This is the art of translating data between different number systems—like going from our familiar decimal system to the binary language of computers. Let's break down these different systems and see how we can "talk" to a machine.
1. What Are Number Systems, Anyway?
Think of a number system as a language for counting. The one we use is called decimal (or base-10) because it uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each position in a decimal number represents a power of 10. For example, in the number 123, the '3' is in the 100 position, the '2' is in the 101 position, and the '1' is in the 102 position.
But computers don't have ten digits. They have two states: on and off, which we represent with the digits 0 and 1. This is the binary system (or base-2). Other systems are used in computing too, like octal (base-8) and hexadecimal (base-16), which are like shortcuts for binary.
2. Decimal to Binary and Back Again
This is the most fundamental conversion in computing. Let's see how it works!
Decimal to Binary The easiest way to convert a decimal number to binary is the repeated division by 2 method. Here's how: Take your decimal number and divide it by 2. Write down the remainder (which will always be 0 or 1). Take the quotient from that division and divide it by 2 again. Repeat this process until your quotient is 0. Your binary number is the sequence of remainders, read from the bottom up!
Example: Let's convert the number 25 to binary.
25÷2=12 remainder 1 12÷2=6 remainder 0 6÷2=3 remainder 0 3÷2=1 remainder 1 1÷2=0 remainder 1
Reading the remainders from bottom to top, we get 11001. So, 2510=110012.
Binary to Decimal To go the other way, you'll use the positional value method.
Write down your binary number. Assign each digit a power of 2, starting from the rightmost digit with 20, and increasing the power by one as you move left. Multiply each digit by its corresponding power of 2. Add up all the results.
Example: Let's convert 110012 back to decimal.
1×24=1×16=16 1×23=1×8=8 0×22=0×4=0 0×21=0×2=0 1×20=1×1=1
Adding these up: 16+8+0+0+1=25. It works!
3. Hexadecimal and Octal: The Binary Shorthands
These systems are super useful for programmers because they can represent long binary numbers in a much more compact way.
Decimal to Hexadecimal This conversion is similar to decimal-to-binary, but you'll divide by 16. Remember, hexadecimal uses the digits 0-9 and then A, B, C, D, E, and F for the values 10 through 15.
Example: Let's convert 255 to hexadecimal.
255÷16=15 remainder 15 (which is F in hex) 15÷16=0 remainder 15 (which is F in hex)
Reading from bottom to top, we get FF. So, 25510=FF16.
Hexadecimal to Decimal To convert from hexadecimal to decimal, you'll use the positional value method again, but with powers of 16.
Example: Let's convert 2A16 to decimal.
A is 10 in decimal. 2×161=2×16=32 10×160=10×1=10
Adding them up: 32+10=42. So, 2A16=4210.
Decimal to Octal This is the same division method, but you'll divide by 8 and use digits 0-7.
Example: Let's convert 75 to octal.
75÷8=9 remainder 3 9÷8=1 remainder 1 1÷8=0 remainder 1
Reading from bottom to top, we get 113. So, 7510=1138.
Octal to Decimal You guessed it, use the positional value method with powers of 8.
Example: Let's convert 1138 to decimal.
1×82=1×64=64 1×81=1×8=8 3×80=3×1=3
Adding them up: 64+8+3=75. Perfect!
Understanding these conversions is a great first step into the world of computer science and a powerful skill to have. Now you're one step closer to truly understanding the digital world!