The best way to remember how to add binary integers is by knowing the way they break down such as, 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 0 but remember to carry the 1 to the next significant bit. In the addition example posted below, the equation is using the 32-bit binary version of the integers 14 and 13 and generating a result of 27.
0000 0000 0000 0000 0000 0000 0000 1110 (14)
+ 0000 0000 0000 0000 0000 0000 0000 1101 (13)
_________________________________________________
0000 0000 0000 0000 0000 0000 0001 1011 (27)
The rules for subtraction can be just as easy by remembering the following rules, 0 – 0 = 0, 1 – 0 = 1, 1 – 1 = 0, and 0 – 1 = 1 but remember to borrow 1 from the next more significant bit. In the subtraction example posted below, the equation is using the 32-bit binary version of the integers 14 and 13 and generating a result of 1.
0000 0000 0000 0000 0000 0000 0000 1110 (14)
- 0000 0000 0000 0000 0000 0000 0000 1101 (13)
_________________________________________________
0000 0000 0000 0000 0000 0000 0000 0001 (1)
Patterson and Hennessy (2014) define overflow as “the result from an operation cannot be represented with the available hardware”. An example of when overflow can occur is when you add two signed positive integers and get a negative integer for the result. For example, a signed 8-bit integer can only go as high as +127. So, when you add 3 to 127 it creates an overflow because the operation cannot be expressed in an 8-bit signed integer. An example of when overflow cannot occur is when you add positive integer and a negative integer as the sum must be no larger than one of the operands. Overflow can occur in subtraction when you subtract a negative number from a positive number and get a negative result, or when you subtract a positive number from a negative number and get a positive result.
References
Shet, R. (2020, February 2). Binary arithmetic - all rules and Operations. Technobyte. Retrieved November 18, 2021, from https://technobyte.org/binary-arithmetic-rules/
Patterson, D. A., & Hennessy, J. L. (2014). Computer organization and design: The hardware/software interface (5th ed.). Retrieved from https://zybooks.zyante.com/
Comments
Post a Comment