DEV Community

Aram Hovhannisyan
Aram Hovhannisyan

Posted on

Binary Representation. Conversion, Addition, Multiplication.

Understanding binary numbers can be much easier when you first look at the decimal numbering system in more detail. In our decimal system, numbers range from 0 to 9. Our decimal system uses 10 as a base. Binary is a base 2 number system made up of only two digits which are 0 and 1. We use these two digits because computers operate with these two numbers. In transistors, which are switch gates for electrical signals, when the input is 1, it means there is a flow of electricity; when it is 0 it means there is no electricity. Computers use the binary system because it is simple and quick to detect an electrical signal's state, and also, the binary is the most efficient way to control logic circuits. Logic gates are basic building blocks for any digital system. A logic gate is an electronic circuit with one or more inputs and only one output. Logic gates are named AND, OR, NOT, XOR, etc. However, let us focus on binary numbers and understand how to perform operations using a binary system.
First, let us understand how to convert binary to decimal. For example, let us take the binary number 1001. As the binary is a base 2 system, each column represents the number two raised to an exponent, with that exponent's value increasing by one when you move through each of the four positions. So we go from the left side to the right. 1 is 2 to the power 0, 0 is 2 to the power 1, the other 0 is 2 to the power 2, and the last 1 is 2 to the power 3. To convert it to a decimal number, we add those values. We get 2^0 plus 2^3 which is 9. We ignored the bits with 0's because they are "turned off." Now let us do the inverse. There is more than one method to do this, but I will use a technique called successive division. So we start with 9 and divide it by 2. We get 4 and the remainder 1. Now we take 4 and divide it by 2. We get 2 and the remainder 0. Now we take 2 and divide it by 2. We get 1 and the remainder 0. And, for the last one, we take 1 and divide it by 2. We get 0 and the remainder 1, and we stop here. At the bottom, we have the most significant bit, and at the top, we have the least significant bit. The way you read it is from the MSB to LSB. So we converted the decimal number 9 into the binary number 1001. Now, let us learn about addition and multiplication. Let us start with the basics. 0 plus 0 is 0, and 1 plus 0 is 1. In the case of 1 plus 1, we will use the carry. 1 plus 1 is 0, but we need to carry over 1, so it is 10. So it basically has the decimal equivalent of 2. If we have 3 1's in a single column, it will produce the output of 11. Let us work on an example. Add numbers 100 and 110. We do the operation from left to right. So, 0 plus 0 is zero, 0 plus 1 is 1, and 1 plus 1 is 10. As a result, we get the number 1010. Now, let us move on to multiplication. We use the same algorithm for base 10 multiplication. Let us see this in the example. What is 101 times 11? 1 times 1 is 1, 1 times 0 is zero, then again 1. Now move to the second column. We get the same result because the numbers are the same. Then we add what we got. The result is 1111.

[https://youtu.be/xHWKYFhhtJQ(url) [https://youtu.be/C5EkxfNEMjE(url) [https://youtu.be/rsxT4FfRBaM(url) [https://www.computerhope.com/jargon/b/binary.htm(url)

Top comments (0)