BINARY ARITHMETIC
Remember the binary numbers? Binary numbers are numbers composed of 0's and 1's. For example, 100 is equal to 4, 010 is equal to 2, 111 is equal to 7, etc. (For other conversions, please refer to my previous blog entry.)In binary arithmetic, we perform addition, subtraction, and other mathematical operations, just like a normal number. But because we are in binary, the end results must also be in binary. Is that even possible? Of course. Normally, 1+1 is equal to 2. How do we express 2 in binary?
Q = quotient; R = remainder |
We're not done yet! In binary arithmetic, of course like in normal decimal numbers, we consider positives and negatives. We cannot simply prefix a minus sign on the binary number if it is a negative. Look at the figure below:
Positive binary numbers
In binary arithmetic, it is wrong to represent 7 as 111. Since 7 is a positive number, we affix a 0 in front. So in binary arithmetic, 7 is 0111.
Negative binary numbers
If we negate a number, for example -7, we simply do not add a 1 to make it 1111. In converting a negative number to a negative binary number, we have what we call a 1's complement and a 2's complement. We first get the 1's complement, then the 2's complement, before we say that the binary number we get is really the negative of the number.
- 1's complement
In 1's complement, we simply take the complement or the reverse of the digits of the binary number. For example, 7, which is 0111, will become 1000 after 1's complement.
- 2's complement
In 2's complement, we simply add 1 to the leftmost digit of the binary number we got from 1's complement. For example, the 2's complement of 7 is 1001, which resulted from 1000+1. 1001 now is -7.
Now how do we check if our conversion is correct?
Remember how we convert binary to decimal?
The conversion of 7 after the 2's complement is 1001 = -7
Now that we are all set, we can perform addition and subtraction.
My personal reactions to this lesson
After the rules have been given to us, and I saw 1 + 1 is equal to 10, and 1 + 1 + 1 is 11, I was like
But then eventually I understood, and as the lesson goes I become more interested on how to apply other mathematical operations in binary numbers, like multiplication and division. I think this lesson is fun though challenging if we increase n, but it's nice to know that we are closer to understanding the basics of the computer's brain. :)
No comments:
Post a Comment