Monday, April 15, 2013

Binary Arithmetic Operations



  • Rules of Binary Addition


0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0, and carry 1 to the next more significant bit
For example,

00011010 + 00001100 = 00100110                1  1 carries
  0  0  0  1  1  0  1  0   =   26(base 10)
+ 0  0  0  0  1  1  0  0
   =   12(base 10)
  0  0  1  0  0  1  1  0   =   38(base 10)


00010011 + 00111110 = 01010001         1  1  1  1  1 carries
  0  0  0  1  0  0  1  1   =   19(base 10)
+ 0  0  1  1  1  1  1  0
   =   62(base 10)
  0  1  0  1  0  0  0  1   =   81(base 10)
Note:  The rules of binary addition (without carries) are the same as the truths of the XOR gate.

http://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#add



  • Binary Subtraction Examples

It's almost exactly the same as decimal subtraction except that when you need to borrow, you borrow 2 instead of 10.

Here are some examples of binary subtraction. These are computed without regard to the word size, hence there can be no sense of "overflow" or "underflow". Work the columns right to left subtracting in each column. If you must subtract a one from a zero, you need to “borrow” from the left, just as in decimal subtraction.

http://sandbox.mc.edu/~bennet/cs110/pm/sub.html

No comments:

Post a Comment