0% found this document useful (0 votes)
26 views12 pages

Arithmetic in Binary

Binary addition and subtraction work on the same principles as decimal, but use only 1s and 0s. 1) In binary addition, if two 1s are added the sum is 0 and there is a carry of 1 to the next column. Carries propagate from right to left. 2) Binary subtraction is the inverse of addition, borrowing 1s from the left when the subtrahend bit is 1 and the minuend bit is 0. 3) Examples show adding and subtracting binary numbers step-by-step and calculating the sum or difference and carry/borrow bit.

Uploaded by

Zay Yar Phyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views12 pages

Arithmetic in Binary

Binary addition and subtraction work on the same principles as decimal, but use only 1s and 0s. 1) In binary addition, if two 1s are added the sum is 0 and there is a carry of 1 to the next column. Carries propagate from right to left. 2) Binary subtraction is the inverse of addition, borrowing 1s from the left when the subtrahend bit is 1 and the minuend bit is 0. 3) Examples show adding and subtracting binary numbers step-by-step and calculating the sum or difference and carry/borrow bit.

Uploaded by

Zay Yar Phyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Programmingknowledge.blogspot.

com Assembly Language- Number System


---------------------------------------------------------------------------------------------------------------------
Arithmetic in Binary

Binary Addition
Binary Number Decimal Number ႔ ။ Binary
Number 1(One) and 0(Zero) ။ Digit ႕
(4) ႔ ။
႔ Binary Number ။ ။
႔ 0(Zero)၊ 1(One)၊ 1+1 Carry 1 ႔ ။၄ (4)

Binary Addition
X Y Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

X Augend
+ Y Addend
Sum with or without a carry

X and Y ႔ Binary Number ။ Sum ႔


Result ။ Carry =1 ႕ Carry
Carry = 0 ။ ။
(၁)။ 11 + 25 = ?
1 1 1 1 - Carry
11  00001011 - Augend
+ 25  + 00011001 - Addend
36 00100100 - Sum
… 1+1 Sum = 0 ႔ Carry = 1 ။
Sum 0 ႕ ႔1 Carry ။ Carry 1
1+1 Sum = 0 ႔ Carry = 1 ။ Sum 0 ႕ ႔1
Carry ။ 1+0 Sum = 1 Carry ။
Sum 1 ။ Binary Addition

/ Decimal Number
႔ ။ 11+25 36 ။ ႔
0 0 1 0 0 1 0 0<2> Decimal Number ။ 36
႔ ။ ၊ ၊ /
Check ႔ ။ ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
(၂)။ 14 + 13 = ?
1 1 - Carry
14  00001110 - Augend
+13  + 00001101 - Addend
27 00011011 - Sum
… 1+1 Sum = 0 ႔ Carry = 1 ။
၄ Sum 0 ႕ ႔1 Carry ။ 1+ 1+ 1
Sum =1 ႔ Carry = 1 ။ Sum 1 ႕ ႔1 Carry
။ 27 ႔ Result
။ ႔ ။
(၃)။ 11.01<2> + 10.11<2> = ?
Solution:
1 1 1 1 - Carry
1 1.0 1 - Augend
+ 1 0.1 1 - Addend
1 1 0.0 0 - Sum
Result: 11.01<2> + 10.11<2> = 110.00<2>
၊ ၊ ႔ Binary Number
႔ ။ ႔ ႕ Binary Number
႔။

Binary Subtraction
Binary Number ။ ႕ Binary Number
inverse operation of addition ႔ ။ ႔ Binary Addition
႔ ႔ ။ ႔ 0(Zero) ၊
1(One) ၊ Borrow 1 ႔ ။ ။
Binary Subtraction
X Y Difference Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0

X - Minuend
- Y - Subtrahend
Difference
X and Y ႔ Binary Number ။ Diffference ႔
Result ။ 0 - 1 Remainder (or) Difference
႔1 ။ ႕
1 ။ ႔ ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
(၁)။ 13 – 5 = ?
Solution:
13  0 0 0 0 1 1 0 1 - Minuend
-5  - 0 0 0 0 0 1 0 1 - Subtrahend
8 0 0 0 0 1 0 0 0 - Difference
။ Binary Bit Binary Bit
႕ Borrow ။ ။ ႔
1 - 1 = 0 ။ Borrow Differerence = 0 ။ ႔
။ ။ 1 - 0 ။
1 - 0 = 1 ။ Borrow Result 1 Difference
။ Result Check ။ 13 - 5 = 8 ၊ ႔
Result 0 0 0 0 1 0 0 0<2> Decimal Number
8 ႔ ။ ။ Borrow
႕ ။
(၂)။ 19 – 8 = ?
Solution:
0 - Borrow
19  0 0 0 1 0 0 1 1 - Minuend
-8  -0 0 0 0 1 0 0 0 - Subtrahend
11 0 0 0 0 1 0 1 1 - Difference
။ ႔ 1-0=1 Difference = 1 ။
။0-0=0 Difference = 0 ။ 0-1
။ Binary Subtraction
Difference=1 ။ ႕ 1 (၅) 1
0 ။ Result Check ။ ႔ ။
႔ ။ Binary Subtraction
။ Borrow ။
(၃)။ 17 – 11 = ?
Solution: 1 1
0 2 2 2 - Borrow
17  0 0 0 1 0 0 0 1 - Minuend
-11  - 0 0 0 0 1 0 1 1 - Subtrahend
6 0 0 0 0 0 1 1 0 - Difference
။ ။ 1-1= 0 Difference = 0
။ 0-1 ။ ႕ 1
။ Binary Number Base 2 ။ ႕ 1
2 ႔ ။ 2 -1 =1 Difference = 1 ။
႔ ။ ႕
။ ႕ ႕ ႕

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
။ Column 5 ။ ။
Column5 = 0 Column4 2 ႔ ။ Column4 Column3 1
Column4 = 1 ။ Column3 Column2
1 Column3 = 1 ။ Column2 ႕ 1
2 2 - 1 = 1 Difference = 1 ။
႔ ။
႔ ႔ Binary Number Binary Subtraction
၊ (၃) 2 ။ ႔
။ Result ။ ႔ Binary
Number ႔ ။
(၄)။ 1.001 – 0.110 = ?
1
Solution: 0 2 2 - Borrow
1.0 0 1 - Minuend
- 0 . 1 1 0 - Subtrahend
0.0 1 1 - Difference
So, 1.001<2> – 0.110<2> = 0.011<2>
၊ ၊ ႔ Binary Number
႔ ။ ႔ ႔ Binary Number
႔ ။
Binary Number Complementation Method ႔
။ ႔ Number System (၁) Complementation Method

Binary Subtraction By Using 1’s Complementation Method


Complementation Method Positive Binary Number Negative Binary Number
(၁) ႔ ။
Binary Number ႕ ။
႕ Negative Binary Number Positive Binary Number ႔
Result ။ 19 – 6 = ? 19 6 ႔
19 + (-6) = ? 19 ႔ -6 ႔ ႔ ။
Binary Number 1’s Complementation Method
။ ႔ ႕ …
1. Binary Number Invert 1’s Complement ။
2. ၄ 1’s complement Binary Number ႔ ။
3. Result End-Carry ၄ End-Carry Reuslt ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
End-Carry ႔ Binary Number (2) Result
။ ။ 1’s Complement ႔
႔ ။
(၁)။ 19 – 6 = ?
Solution:
19<10> Minuend  0 0 0 1 0 0 1 1<2>
6<10> Subtrahend  0 0 0 0 0 1 1 0<2>
1’s complement of Subtrahend (6<10>)  1 1 1 1 1 0 0 1<2>
Add this complement to Minuend(19<10> ):
19  0 0 0 1 0 0 1 1
1’s complement of 6  + 1 1 1 1 1 0 0 1
1 0 0 0 0 1 1 0 0
+ 1
0 0 0 0 1 1 0 1  13
So, 19 – 6 = 0000 1101<2>
။ ႔ 6<10> = 0000 0110<2> Invert
1’s Complement ။ ႔ 1’s complement 0000
0110<2> ႕ 19<10> = 0001 0011<2> ႔ ။ End-
Carry ၄ End-Carry Result ႔ ။
Binary Number ႔ Binary Addition
႔ ႔ ။ Result Check
။ 0000 1101<2> = 13<10> ႔ ။ 19 – 6 = 13 ။
႔ ။

(၂)။ 17 – 8 = ?
Solution:
17<10> Minuend  0 0 0 1 0 0 0 1<2>
8<10> Subtrahend  0 0 0 0 1 0 0 0<2>
1’s complement of Subtrahend(8<10>)  1 1 1 1 0 1 1 1<2>
Add this complement to Minuend(17<10>) :
17  0 0 0 1 0 0 0 1
1’s complement of 8  + 1 1 1 1 0 1 1 1
1 0 0 0 0 1 0 0 0
+ 1
0 0 0 0 1 0 0 1 9
So, 17 – 8 = 0000 1001<2>
… ႔ 8<10> = 0000 1000<2> Invert
1’ s Complement ။ ႔ 1’s Complement
0000 1000<2> ႕ 17<10> = 0001 0001<2> ႔ ။
End-Carry ၄ End-Carry Result ႔
။ ။ Result Check

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
0000 1001<2> = 9<10> ႔ ။ ။
႔ ႔ ႔ ။
(၃)။ 11.01 – 01.10 = ?
Solution:
Minuend  1 1.0 1<2>
Subtrahend  0 1.1 0<2>
1’s complement of Subtrahend  1 0.0 1<2>
Add this complement to Minuend:
Minuend  11.01
1’s complement of Subtrahend  + 10.01
1 01.10
+1
0 1 . 1 1  Difference
So, 11.01<2> – 01.10<2> = 01.11<2>
၊ ၊ ႔ 1’s Complementation Method
Binary Number ႔ ။ Binary Number
2’s Complementation Method ႔။

Binary Subtraction By Using 2’s Complementation Method


1’s Complementation Method ႔ ။
Binary Number ႕ ။ ႕ Negative Binary Number
Positive Binary Number ႔ Result ။
17 – 5 = ? 17 5 ႔ 17 + (-5) = ? 17 ႔ -5
႔ ႔ ။
Binary Number 2’s Complementation Method
။ ႔ ႕ …
1. Binary Number Invert 1’s Complement ။
2. ၄ 1’s complement Binary Number 1 2’s Complement ။
3. 2’s Complement ( ႔) -Negative Binary Number
Binary Number ႔ ။
4. Result End-Carry ၄ End-Carry ignored Result ။
End-Carry Result 2’s Complement
႕ Result ။ ။ 2’s
Complement ႔ ႔

(၁)။ 17 – 5 = ?
Solution:
17 + (- 5) = 12
17<10> Minuend  0 0 0 1 0 0 0 1<2>

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
5<10> Subtrahend  0 0 0 0 0 1 0 1<2>
1’s complement of Subtrahend(5<10> )  1 1 1 1 1 0 1 0<2>
2’s complement of Subtrahend(5<10> )  11111010
+ 1
1 1 1 1 1 0 1 1  -5
Add this 2’s complement to Minuend(17<10>):
17  00010001
+(-5)  + 11111011
12 1 0 0 0 0 1 1 0 0  Difference
End-Carry is ignored. So, 17 – 5 = 0000 1100<2>
။ ။ 5<10> = 0000 0101<2>
Invert 1’ s Complement ။ ႔ 1’s Complement
0000 0101<2> ႕ 1 2’s complement ။
Positive Binary Number Negative Binary Number
။ ႔ -5 ႕ Binary Number ။
၄ Negative Binary Number 17<10> = 0001 0001<2> ႔ ။
End-Carry ၄ End-Carry Result
။ ။
Result Check ။ 17 – 5 =12 ႔
Binary Number ႕ 12 ။
End-Carry ။ ႔ ႔
End-Carry ႔ ။

(၂)။ 10 – 24 = ?
Solution:
10 + (-24) = -14
10<10> Minuend  0 0 0 0 1 0 1 0<2>
24<10> Subtrahend  0 0 0 1 1 0 0 0<2>
1’s complement of Subtrahend(24<10>)  1 1 1 0 0 1 1 1<2>

2’s complement of Subtrahend(24<10>) 11100111


+ 1
1 1 1 0 1 0 0 0  -24
Add this 2’s complement to Minuend(10<10>):
10  00001010
-24  +11101000
-14 1 1 1 1 0 0 1 0  Difference
No End-Carry. So,
1’s complement of -14  00001101

2’s complement of -14  00001101


+ 1
0 0 0 0 1 1 1 0  14
Result: 10 – 24 = 1111 0010<2> (or) 10 – 24 = - 0000 1110<2>
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
။ (၁) ။ 24<10> = 0001 1000<2>
Invert 1’ s Complement ။ ႔ 1’s
Complement 0001 1000<2> ႕ 1 2’s complement ။
Positive Binary Number Negative Binary Number
။ ႔ -24 ႕ Binary Number ။
၄ Negative Binary Number 10<10> = 0000 1010<2> ႔
။ End-Carry ႔ ႕ Result
-14<10> = 11110010<2> ။ Check ။ 10 – 24 = -14
။ -14 ႕ Binary

႔ Positive Binary Number ႕ Minus Sign
Two Complement ။ Binary Two
Complement Method Positive Negative ၊ Negative Positive
။ ။ ႔ ႔ -14 ႕
Binary Two Complement ႔ +14 ႕ Binary ။၄ +14
႕ ႔ ။

End-Carry ။ ႔
။ ႔ ႔ Minus ႔ ၊ Plus
Minus Sign ။ ။
2’s completation method ႔
႔။
(၃)။ 111.001 – 10.110 = ?
Solution:
Minuend 111.001
Subtrahend 010.110
1’s complement of Subtrahend  101.001

2’s complement of Subtrahend  101.001


+ 1
101.010

Adding the 2’s complement of Subtrahend to Minuend:


Minuend  111.001
2’s complement of Subtrahend  +101.010
1 1 0 0 . 0 1 1  Difference
End-Carry is ignored. So, 111.001 – 10.110 = 100.011<2>
၊ ၊ ႔ Binary Number
Binary Subtraction Method, 1’s completation method and 2’s

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
complementation method ႔
။ ႕ ၊ ႔
႔ ႔ ႔ ။

Binary Multiplication
Binary Number Decimal Number
႔ ။ ႔ ႔ General Rule
။ ။
Binary Multiplication
X Y XxY
0 0 0
0 1 0
1 0 0
1 1 1

X - Multiplicand
x Y - Multiplier
Products
X and Y ႔ Binary Number ။ Products ႔
Result ။ ႔1x1 1
0(Zero) ႔ ။ ။

(၁)။ 12 x 9 = ?
Solution:
12  1 1 0 0 - Multiplicand
9  x 1 0 0 1 - Multipler
1100
0000
0000
+1100 _
108  1 1 0 1 1 0 0 - Products
So, 12 x 9 = 1101100<2>

႔ Result ႔ ႔
။ Binary Number Decimal Number ႔ ။
1x1 1 0 ။
Result Decimal Number ႔ Check ။ Result ။
၊ ႔ ႔ ။ ႔ ႔
Decimal Number ႔ Check ႔ ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
(၂)။ 9 x 5 = ?
Solution:
9  1 0 0 1 - Multiplicand
5  x 1 0 1 - Multiplier
1001
0000
+1001 _
45  1 0 1 1 0 1 - Products
So, 9 x 5 = 101101<2>
Binary Number ။ ႔ ။
၊ ၊ ႔ ႔

(၃)။ 3.5 x 1.5 = ?
Solution:
3.5  1 1.1 - Multiplicand
1.5  x 1.1 - Multiplier
111
+111 _
5.25  1 0 1.0 1 - Products
So, 3.5 x 1.5 = 101.01<2>
Result ။ Decimal Number ႔ ။
။ ။
(၄)။ 10.5 x 4.5 = ?
Solution:
10.5  1 0 1 0.1 - Multiplicand
4.5  x 1 0 0.1 - Multiplier
10101
00000
00000
+10101 _
47.25  1 0 1 1 1 1.0 1 - Products
So, 10.5 x 4.5 = 101111.01<2>
၊ ၊ ႔ Binary Number
႔ ။ Binary Division

Binary Division
Binary Division Decimal Division ႔ ။ ႔
Left to Right ။ Digit
။ Decimal Number
႔ ။ Binary Division ၊ ၊

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
႔ General Rule ။ ႔ ႔
႔ ။
(၁)။ 22 / 3 = ?
Solution:
Dividend 22  10110<2>
Divisor 3  11<2>

Quotient
Divisor Dividend

Quotient
Divisor

Remainder Remainder
Decimal Division Binary Division
So, 22 / 3  Quotiend = 111<2> And Remainder = 1
႔ ။ Binary Division ။
႔ Left to Right ။ Digit 10<2>
။ 101<2>
။ ။ 101-11 = 10
။ ႕ 1 ။
101-11 = 10 ။ ႕ 0
။ 100-11 =1 ႔ ။ ႔ 22/3 ႕
-111 -1 ။ ။

(၂)။ 15 / 4 = ?
Solution:
Dividend 15  1111<2>
Divisor 4  100<2>

Quotient

Divisor Dividend

Quotient
Divisor

Remainder Remainder
Decimal Division Binary Division
So, 15 / 4  Quotiend = 11<2> And Remainder = 11<2>

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com Assembly Language- Number System
---------------------------------------------------------------------------------------------------------------------
Binary Number ႔ ႔ ႔
။ ႔ ။ Binary
Subtraction ႔ ။

႔ ႕
။ Arithmetic in Octal Octal Number
၊ ၊ ၊ … ႔ ။
၊ ၊ ။

Assembly Language ႕ Number System (၂) ။


႔ ။
၊ ၊
႔ ။
႔ ၊ ။
႔ ၏ ႔…
႔၏ ႔… ။

Tay Zar Lin


[email protected]
Programmingknowledge.blogspot.com

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။

You might also like