Computer Science, convert binary into decimal and vice versa.
When it comes to computers, we often encounter a different number system than the one we are accustomed to using in our daily lives. While we rely on the decimal system, computers operate using the binary system. This fundamental difference is crucial to comprehend, as it allows us to gain a deeper understanding of computer logic and how they perform various operations.
The decimal system, also known as the deca system, is the number system we use in our everyday lives. It is based on “Base 10,” meaning that after every ten numbers, we increase the value of the next magnitude. For example, we have 1, 10, 100, 1000, and so on. When we add 1 to 9, the one’s place resets to 0, and the next magnitude increases. Hence, we get the number 10. Similarly, if we have 99 and add 1, the one’s spot resets to 0, and the ten’s spot increases by one. Since there is already a 9 in this spot, it also resets to 0, and the next spot increments by 1, resulting in the number 100. This pattern of adding an additional zero for each magnitude makes arithmetic easier in the decimal system.
On the other hand, the binary system used by computers operates with only two numbers: 0 and 1. This limitation arises from the fact that computers rely on electricity, which has two reliable states — on (1) and off (0). Computers cannot reliably read anything in between, so all their operations are based on the binary system. Inside a CPU processor, there are millions of tiny switches that work together, combining and rearranging 1s and 0s to perform computations.
Unlike the decimal system, the binary system follows “Base 2.” Each new position represents a power of 2. For instance, the first position is 2⁰, the second position is 2¹, the third position is 2², and so on. To compare the deca and binary systems, let’s break down the number 1,578,483 in both systems.
In the decimal system, we add up each number multiplied by its corresponding magnitude. For 1,578,483, the calculation is as follows: 1,000,000 + 500,000 + 70,000 + 8,000 + 400 + 80 + 3 = 1,578,483.
In the binary system, the transition between each number is much smaller. The number 1011111 represents the decimal number 95. Instead of using powers of 10 as in the decimal system, the binary system uses powers of 2. For example, the sixth place in the binary system represents 64, whereas in the decimal system, it represents 1,000,000.
Convert a binary number to decimal
Converting between binary and decimal numbers is relatively straightforward. To convert a binary number to decimal, we add up the magnitudes with a 1 in them. For example, 1011 in binary would be converted to 8 + 0 + 2 + 1 = 11 in decimal. (2³ + 2¹ + 2⁰)
Converting from decimal to binary
Converting from decimal to binary requires subtracting the largest number that fits without exceeding the decimal value. For example, to convert 55 to binary, we subtract the largest power of 2, which is 32, from the decimal number. Then, we repeat this process until the number reaches zero. Any remaining positions without a 1 are filled with 0s. Thus, 55 in decimal becomes 110111 in binary.
Let’s draw binary tables
2⁵, 2⁴, 2³, 2², 2¹, 2⁰
If we try to convert 55 to binary, for each number you encounter in the table, ask yourself if 55 can be subtracted from the value represented(2⁶, 2⁵…). If it can be subtracted, it becomes 1. And ask another question if remainder 23( 55 minus 32 ) can be subtracted with 2⁴.. and so on….
Conclusion
Understanding binary and decimal number systems is vital for anyone interested in computer science and computing in general. It provides insights into the foundational principles that govern.