Chapterبەش 3 · Lectureوانە 3.1
Binary Addition and Subtractionکۆکردنەوەی دووانی و لێدەرکردنی دووانی
Add and subtract binary numbers column by column: the four addition rules and , carries that ripple, the subtraction rules with borrows, borrowing across zeros, and how to check your answers.
کۆکردنەوە و لێدەرکردنی ژمارە ستوون بە ستوون: چوار یاساکەی کۆکردنەوە و ، و ڕۆیشتنیان بە ناو ستوونەکاندا، یاساکانی لێدەرکردن بە ، بە ناو سفرەکاندا و چۆنیەتیی پشکنینی وەڵامەکانت.
What you will learnچی فێر دەبیت
- Use the four binary addition rules and the case.
- Add binary numbers of any length with a carry row.
- Explain what happens when a sum needs one bit more than a fixed-width register has.
- Subtract binary numbers with borrows, also across zeros.
- Check an answer in decimal or by adding back.
- چوار یاساکەی و حاڵەتی بەکاربهێنیت.
- ژمارەی بە هەر درێژییەک بە ڕیزی کۆ بکەیتەوە.
- ڕوونی بکەیتەوە چی ڕوودەدات کاتێک کۆیەک یەک زیاتری پێویستە لەوەی قەبارە جێگیر هەیەتی.
- ژمارەی بە لێ دەربکەیت، بە ناو سفرەکانیشدا.
- وەڵامێک بە یان بە کۆکردنەوەی دووبارە بپشکنیت.
Arithmetic with only two digitsژمێرکاری تەنها بە دوو تاکژمارە
Binary arithmetic is an essential part of every digital computer and of many other digital systems. Inside a processor, adding bits is one of the most common jobs: everything from moving a mouse pointer to showing a video ends up as additions of bits.
ژمێرکاریی بەشێکی سەرەکیی هەموو و زۆر سیستەمی ترە. لە ناو کۆکردنەوەی یەکێکە لە باوترین کارەکان: هەموو شتێک، لە جووڵاندنی ماوسەوە تا پیشاندانی ڤیدیۆ، لە کۆتاییدا دەبێتە کۆکردنەوەی .
This chapter of the course covers, in order:
ئەم بەشەی کۆرسەکە بەم ڕیزبەندییە ئەمانە فێر دەکات:
- The rules of binary addition and subtraction (this lesson), then multiplication and division.
- 1's and 2's complements.
- Sign-magnitude form and other ways to store negative numbers (signed numbers).
- The next chapter then turns to codes: BCD, the Gray code and ASCII.
- یاساکانی و (ئەم وانەیە)، پاشان لێکدان و دابەشکردن.
- تەواوکەری یەک و تەواوکەری دوو.
- شێوەی و ڕێگاکانی تری هەڵگرتنی (ژمارە نیشانەدارەکان).
- پاشان بەشی دواتر دەچێتە سەر کۆدەکان: ، و .
The good news: you already know the method from decimal. Only one thing changes. In decimal a column overflows when it reaches 10; in binary it overflows when it reaches 2.
هەواڵی خۆش: ڕێگاکە لە دەزانیت. تەنها یەک شت دەگۆڕێت. لە ستوونێک کاتێک پڕ دەبێت کە دەگاتە 10؛ لە کاتێک کە دەگاتە 2.
The four addition rules (and one more)چوار یاساکەی کۆکردنەوە (و یەکێکی تر)
Adding two bits has only four possible cases. The last one is the interesting one: , and 2 in binary is 10. So you write 0 and carry 1, exactly like in decimal, where you also write 0 and carry 1.
کۆکردنەوەی دوو تەنها چوار حاڵەتی هەیە. دواینیان سەرنجڕاکێشە: و 2 لە 10ـە. کەواتە 0 دەنووسیت و 1 دەگوازیتەوە، ڕێک وەک لە ، کە لەوێش 0 دەنووسیت و 1 دەگوازیتەوە.
| Caseحاڵەت | Sum bit ئەنجام | Carry | |
|---|---|---|---|
| 1 | 0 | 0 | |
| 2 | 1 | 0 | |
| 3 | 1 | 0 | |
| 4 | 0 | 1 | |
| with a carry inلەگەڵ هاتوو | 1 | 1 |
Later, in Adders, you will meet a small circuit, the full adder, that does exactly this job for one column: it takes two bits and a carry in, and gives a sum bit and a carry out.
دواتر لە کۆکەرەوەکان بچووک دەناسیت، ، کە ڕێک ئەم کارە بۆ یەک ستوون دەکات: دوو و هاتوو وەردەگرێت و ئەنجام و بۆ ستوونی دواتر دەدات.
Why the carry comes at twoبۆچی گواستراوە لە دوودا دێت
In the bazaar, when you have ten 1,000-dinar notes you can change them for one 10,000-dinar note. That swap is the decimal carry: ten of one kind become one of the next kind. Now imagine a shop whose notes are worth 1, 2, 4, 8 … and where two notes of one kind are always swapped for one note of the next kind. That is binary: the carry happens at two.
لە بازاڕدا کاتێک دە دانە پارەی 1,000 دیناریت هەبێت، دەتوانیت بیانگۆڕیتەوە بە یەک پارەی 10,000 دینار. ئەو گۆڕینەوەیە : دە دانە لە جۆرێک دەبنە یەک دانە لە جۆری دواتر. ئێستا دووکانێک بهێنە بەرچاوی خۆت کە پارەکانی بەهای 1، 2، 4، 8 ... یان هەیە و هەمیشە دوو پارەی یەک جۆر بە یەک پارەی جۆری دواتر دەگۆڕێتەوە. ئەوە : گواستنەوە لە دوودا ڕوودەدات.
Where the analogy stops workingسنووری ئەم نموونەیە
No real money works like this, and a wallet can hold many notes of one kind. In binary every column is worth exactly twice the column on its right, and each column holds only 0 or 1.
هیچ پارەیەکی ڕاستەقینە بەم شێوەیە نییە و جزدان دەتوانێت چەندین پارەی یەک جۆر هەڵبگرێت. لە هەر ستوونێک ڕێک دوو هێندەی ستوونی لای ڕاستی بەهای هەیە و هەر ستوونێک تەنها 0 یان 1 هەڵدەگرێت.
Adding column by columnکۆکردنەوە ستوون بە ستوون
Write the two numbers under each other with their right ends lined up. Start at the right-hand column. In every column add the two bits and the carry that came in, write the sum bit underneath and carry the rest to the next column on the left. Watch the carry travel through every column of :
دوو ژمارەکە لە ژێر یەکتر بنووسە و سەری ڕاستیان ڕێک لە ژێر یەک بێت. لە ستوونی لای ڕاستەوە دەست پێبکە. لە هەر ستوونێکدا دوو و ئەو هاتووە کۆ بکەرەوە، ئەنجام لە خوارەوە بنووسە و ئەوەی دەمێنێتەوە بگوازەرەوە بۆ ستوونی دواتری لای چەپ. سەیر بکە چۆن بە هەموو ستوونەکانی دا دەڕوات:


The finished layout. The small 1s on the top row are the carries, each written above the column it goes into. Check in decimal: and .
شێوەی تەواوبوو. 1ـە بچووکەکانی ڕیزی سەرەوە ، هەریەکەیان لە سەر ئەو ستوونە نووسراوە کە دەچێتە ناوی. پشکنین بە : و .
Adding binary numbers column by column from the right, writing each carry above the next column.
کۆکردنەوەی ژمارەکانی ستوون بە ستوون لە ڕاستەوە، کە هەر لە سەرووی ستوونی دواترەوە دەنووسرێت.
Numbers of different lengthsژمارەی درێژیی جیاواز
When the numbers have different lengths, line up the right ends, never the left ends. Zeros on the left do not change a value, so you may add them to make the columns easy to see: 11 is the same as 011.
کاتێک ژمارەکان درێژییان جیاوازە، سەری ڕاستیان ڕێک بخە، هەرگیز سەری چەپیان نا. سفری لای چەپ بەها ناگۆڕێت، بۆیە دەتوانیت زیادی بکەیت تا ستوونەکان ئاسان ببینرێن: 11 هەمان 011ـە.
: every column produces a carry, and the final carry makes the answer one bit longer than both numbers.
: هەموو ستوونێک دروست دەکات و دوایین وەڵامەکە یەک لە هەردوو ژمارەکە درێژتر دەکات.
When the answer does not fitکاتێک وەڵامەکە جێی نابێتەوە
Adding two n-bit numbers can give an answer with bits, as in . On paper that is no problem. A computer, however, keeps each number in a with a fixed number of bits. Watch a 5-bit register add ():
کۆکردنەوەی دوو ژمارەی n دەتوانێت وەڵامێکی بدات، وەک . لەسەر کاغەز ئەمە کێشە نییە. بەڵام هەر ژمارەیەک لە هەڵدەگرێت کە ژمارەی جێگیرە. سەیر بکە 5 چۆن () کۆ دەکاتەوە:
The true sum is , six bits. The sixth bit (crossed out) has no place in the register, so the register keeps only .
کۆی ڕاستەقینە ـە، شەش . شەشەم (خەتلێدراوەکە) لە جێی نییە، بۆیە تەنها دەهێڵێتەوە.
For unsigned numbers this lost carry is the : the stored answer, 9 instead of 41, is wrong. The processor notices, because the carry out of the last column is 1, and records it in a special status bit (the carry flag) so that a program can react. Signed numbers are judged differently: there, a carry out of the last column is often harmless.
بۆ ئەم ونبووە خۆی ـە: وەڵامە هەڵگیراوەکە، 9 لە جیاتی 41، هەڵەیە. هەستی پێدەکات، چونکە دوایین ستوون 1ـە و لە تایبەتدا تۆماری دەکات (carry flag) تا بتوانێت کاردانەوەی هەبێت. ژمارە نیشانەدارەکان بە شێوەیەکی تر هەڵدەسەنگێنرێن: لەوێ کە لە دوایین ستوون دەردەچێت زۆرجار زیانی نییە.
Adding binary numbers in a fixed number of bits, and what an overflow is when the carry has nowhere to go.
کۆکردنەوەی ژمارەکانی لە ژمارەیەکی جێگیری ، هەروەها چییە کاتێک هیچ شوێنێکی نییە.
From 2:30 (binary example) through 5:42 (overflows) to the end.
لە 2:30ـەوە (نموونەیەکی ) تا کۆتایی، لەوانە بەشی لە 5:42.
The four subtraction rulesچوار یاساکەی لێدەرکردن
Binary subtraction is a little more difficult than addition, because of one case: . A column cannot give 1 when it has 0, so it borrows 1 from the column on its left. That borrowed 1 is worth 2 in this column (), and .
کەمێک لە کۆکردنەوە قورسترە، لەبەر یەک حاڵەت: . ستوونێک کە 0ـی هەیە ناتوانێت 1 بدات، بۆیە لە ستوونی لای چەپییەوە 1 دەخوازێت. ئەو 1ـە خوازراوە لەم ستوونەدا بەهای 2ـە () و .
| Caseحاڵەت | Differenceجیاوازی | Borrow | |
|---|---|---|---|
| 1 | 0 | 0 | |
| 2 | 1 | 0 | |
| 3 | 0 | 0 | |
| 4 | 1 |
The four binary subtraction rules and how a borrow works, with a worked example.
چوار یاساکەی و چۆن کار دەکات، لەگەڵ نموونەیەکی شیکراوە.
Chapter 6:25 "Binary Subtraction Rules" (to 11:14).
بەشی 6:25، Binary Subtraction Rules (تا 11:14).
Borrowing is breaking a noteخواستن وەک وردکردنی پارە
You must pay 7,000 dinars but your small notes are only two 1,000-dinar notes. So you change one 10,000-dinar note into ten 1,000-dinar notes: now you can pay. Borrowing in subtraction is the same, but in binary the big note only breaks into two small ones.
دەبێت 7,000 دینار بدەیت، بەڵام پارە وردەکانت تەنها دوو دانە 1,000 دینارین. بۆیە یەک پارەی 10,000 دینار دەگۆڕیتەوە بە دە دانە 1,000 دینار: ئێستا دەتوانیت بیدەیت. لە لێدەرکردندا هەمان شتە، بەڵام لە پارە گەورەکە تەنها دەبێتە دوو پارەی بچووک.
Where the analogy stops workingسنووری ئەم نموونەیە
In the bazaar you choose which note to break. In subtraction you always borrow from the column directly on the left, even if it holds 0; then that column has to borrow too.
لە بازاڕدا خۆت هەڵدەبژێریت کام پارە ورد بکەیت. لە لێدەرکردندا هەمیشە لە ستوونی ڕاستەوخۆی لای چەپ دەخوازیت، تەنانەت ئەگەر 0ـیش بێت؛ ئەو کاتە ئەو ستوونەش دەبێت بخوازێت.
When a borrow comes inکاتێک خواستن دێت
A column that lent 1 to its right neighbour must subtract 1 more. So once borrows start, each column computes top − bottom − borrow. If the result is below 0, add 2 and borrow from the next column. The four extra cases:
ستوونێک کە 1ـی بە دراوسێی لای ڕاستی قەرز داوە، دەبێت 1ـی زیاتر لێ دەربکات. کەواتە کە دەستی پێکرد، هەر ستوونێک ئەمە دەکات: سەرەوە − خوارەوە − . ئەگەر ئەنجام لە 0 کەمتر بوو، 2ـی بخەرە سەر و لە ستوونی دواتر بخوازە. چوار حاڵەتە زیادەکە:
| − borrow in − هاتوو | Differenceجیاوازی | Borrow out بۆ ستوونی دواتر |
|---|---|---|
| 1 | 1 | |
| 0 | 1 | |
| 0 | 0 | |
| 1 | 1 |
These four rows are the subtraction partner of the row in addition. With them you can do any subtraction column by column.
ئەم چوار ڕیزە هاوتای ڕیزی ـن لە کۆکردنەوەدا. بە یارمەتییان دەتوانیت هەموو لێدەرکردنێک ستوون بە ستوون بکەیت.
Subtracting column by columnلێدەرکردن ستوون بە ستوون
Here is (). In the layout, a small 1 above a column means: this column lent 1 to its right neighbour, so subtract 1 more here.
ئەمە ـە (). لە شێوەکەدا، 1ـێکی بچووک لە سەر ستوونێک واتە: ئەم ستوونە 1ـی بە دراوسێی لای ڕاستی قەرز داوە، بۆیە لێرەدا 1ـی زیاتر لێ دەربکە.
Right column: . No borrow.
ستوونی ڕاست: . هیچ نییە.
Second column: is below 0. Borrow 1 from the left; it is worth 2 here: .
ستوونی دووەم: لە 0 کەمترە. لە لای چەپ 1 بخوازە؛ لێرە بەهای 2ـە: .
Third column: it lent 1, so , below 0 again. Borrow from the left: .
ستوونی سێیەم: 1ـی قەرز داوە، بۆیە ، دیسان لە 0 کەمترە. لە لای چەپ بخوازە: .
Left column: it lent 1, so .
ستوونی چەپ: 1ـی قەرز داوە، بۆیە .
Answer , and .
وەڵام و .
Borrowing across zerosخواستن بە ناو سفرەکاندا
What if the column on the left is 0? Then it cannot lend at once: it borrows from its left neighbour first, and the borrow travels left until it reaches a 1. You know this from decimal: in the borrow passes two zeros, and they become 9s (997). In binary the zeros it passes become 1s.
ئەی ئەگەر ستوونی لای چەپ 0 بێت؟ ئەو کاتە ناتوانێت یەکسەر قەرز بدات: سەرەتا خۆی لە دراوسێی لای چەپی خۆی دەخوازێت و بەرەو چەپ دەڕوات تا دەگاتە 1ـێک. ئەمە لە دەزانیت: لە دا بە سەر دوو سفردا تێدەپەڕێت و دەبنە 9 (). لە ئەو سفرانەی پێیاندا تێدەپەڕێت دەبنە 1.


The finished layout: three borrows in a row. Check: .
شێوەی تەواوبوو: سێ لە دوای یەک. پشکنین: .
Checking a subtraction, and negative answersپشکنینی لێدەرکردن و وەڵامی سالب
A subtraction is easy to check: difference + bottom number = top number. For , add back:
پشکنینی لێدەرکردن ئاسانە: جیاوازی + ژمارەی خوارەوە = ژمارەی سەرەوە. بۆ ، بیخەرەوە سەری:
: the top number comes back, so the subtraction was right.
: ژمارەی سەرەوە دەگەڕێتەوە، کەواتە لێدەرکردنەکە دروست بووە.
If the bottom number is bigger, a borrow is left over at the far left with no column to pay it, for example in (). The real answer, , is negative, and plain binary has no minus sign. Computers solve this with complements: they even subtract by adding the 2's complement, so one adder circuit does both jobs. See 1's and 2's complements and signed arithmetic.
ئەگەر ژمارەی خوارەوە گەورەتر بێت، لە تەواو لای چەپ دەمێنێتەوە و هیچ ستوونێک نییە بیداتەوە، بۆ نموونە لە دا (). وەڵامی ڕاستەقینە، ، و سادە نیشانەی سالبی نییە. ئەمە بە تەواوکەرەکان چارەسەر دەکەن: تەنانەت بە کۆکردنەوەی لێدەردەکەن، بۆیە یەک هەردوو کارەکە دەکات. بڕوانە تەواوکەری یەک و تەواوکەری دوو و ژمێرکاریی ژمارە نیشانەدارەکان.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | What goes wrongچی تێکدەچێت | Fixچارەسەر |
|---|---|---|
| Writing نووسینی | 2 is not a binary digit2 نییە | Write 0, carry 1 ()0 بنووسە و 1 بگوازەرەوە () |
| Forgetting a carryلەبیرکردنی | The answer is too smallوەڵامەکە زۆر بچووک دەبێت | Write each carry above its column before adding that columnپێش کۆکردنەوەی هەر ستوونێک لە سەری بنووسە |
| Lining up the left endsڕێکخستنی سەری چەپ | Bits of different weights are added کێشی جیاواز کۆ دەکرێنەوە | Line up the right ends; pad with zeros on the leftسەری ڕاست ڕێک بخە؛ لە لای چەپ سفر زیاد بکە |
| Treating as 1 with no borrow بە 1 دانان بێ | The left column is 1 too bigستوونی چەپ 1 زیاتر دەبێت | Borrow, then subtract 1 more in the next columnبخوازە، پاشان لە ستوونی دواتر 1ـی زیاتر لێ دەربکە |
| Calling the borrow a carryناونانی بە | Confuses addition and subtractionکۆکردنەوە و لێدەرکردن تێکەڵ دەکات | Carry = addition, borrow = subtraction = کۆکردنەوە، = لێدەرکردن |
The safest habit: after every exam answer, convert the numbers to decimal and check (, …). It takes a moment and catches almost every slip.
باشترین خوو: دوای هەر وەڵامێکی تاقیکردنەوە، ژمارەکان بگۆڕە بۆ و بیپشکنە (، ...). تەنها چەند چرکەیەکی دەوێت و نزیکەی هەموو هەڵەیەک دەگرێت.
Exercisesڕاهێنانەکان
These are the lecture's exercises. Do them on paper with the carry or borrow row, then compare with the layouts in the answers.
ئەمانە ڕاهێنانەکانی وانەکەن. لەسەر کاغەز بە ڕیزی یان بیانکە، پاشان لەگەڵ شێوەکانی ناو وەڵامەکاندا بەراوردیان بکە.
Add: (a) (b) (c) (d) (e) (f)
کۆ بکەرەوە: (أ) (ب) (ج) (د) (هـ) (و)
Hintئاماژە
Line up the right ends and write every carry above the next column.
سەری ڕاست ڕێک بخە و هەموو لە سەر ستوونی دواتر بنووسە.
Show answerوەڵامەکە پیشان بدە
Subtract: (a) (b) (c) (d)
لێ دەربکە: (أ) (ب) (ج) (د)
Hintئاماژە
When the top bit is too small, borrow from the left and subtract 1 more in that column.
کاتێک سەرەوە بچووک بوو، لە لای چەپ بخوازە و لەو ستوونەدا 1ـی زیاتر لێ دەربکە.
Show answerوەڵامەکە پیشان بدە
Zeros at the left of a difference can be dropped: and .
سفرەکانی لای چەپی جیاوازی دەتوانرێت لاببرێن: و .
Check exercise 2(d) by adding the difference and the bottom number.
ڕاهێنانی 2(د) بپشکنە بە کۆکردنەوەی جیاوازی و ژمارەی خوارەوە.
Show answerوەڵامەکە پیشان بدە
: the top number comes back.
: ژمارەی سەرەوە دەگەڕێتەوە.
Summaryپوختە
- Addition: , , , (write 0, carry 1), and with a carry in .
- Subtraction: , , , with a borrow ().
- Work from the right; write carries and borrows above the columns.
- A carry or a borrow can ripple through many columns.
- Check: convert to decimal, or add the difference back.
- کۆکردنەوە: ، ، ، (0 بنووسە و 1 بگوازەرەوە) و لەگەڵ هاتوو .
- لێدەرکردن: ، ، ، لەگەڵ ().
- لە لای ڕاستەوە کار بکە؛ و لە سەر ستوونەکان بنووسە.
- یان دەتوانێت بە چەندین ستووندا بڕوات.
- پشکنین: بگۆڕە بۆ ، یان جیاوازییەکە بخەرەوە سەری.
Why is written as 10 in binary?بۆچی لە دووانیدا بە 10 دەنووسرێت؟
Because , and 2 is written 10 in base 2: one 2 and no 1s.
چونکە و 2 لە 2دا بە 10 دەنووسرێت: یەک دانە 2 و هیچ 1ـێک.
What is the difference between a carry and a borrow?جیاوازیی نێوان گواستراوە و خواستن چییە؟
A carry goes to the left column in addition (it adds 1 there); a borrow is taken from the left column in subtraction (it subtracts 1 there).
لە کۆکردنەوەدا دەچێتە ستوونی چەپ (لەوێ 1 زیاد دەکات)؛ لە لێدەرکردندا لە ستوونی چەپ وەردەگیرێت (لەوێ 1 کەم دەکاتەوە).
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Kurdish lecture: binary addition with carries, subtraction with borrows, then multiplication and long division.
وانەیەکی کوردی: لەگەڵ ، لەگەڵ ، پاشان لێکدان و دابەشکردنی درێژ.
Kurdish. Addition rules (1 + 1 = 10, 1 + 1 + 1 = 11) and subtraction examples; ends before multiplication at about 7:55 (checked frames).
بە کوردی. یاساکانی کۆکردنەوە (، ) و نموونەکانی لێدەرکردن؛ نزیکەی 7:55، پێش لێکدان، کۆتایی دێت (لە وێنەکانی ڤیدیۆکەوە پشکنراوە).
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Binary Multiplication and Divisionلێکدانی دووانی و دابەشکردنی دووانی
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Wikipedia: Binary number (binary arithmetic: addition, carries, subtraction with borrows)
- MIT 6.004 Computation Structures notes: Basics of information (binary addition in a fixed number of bits)
- Wikipedia: Two's complement (how computers subtract by adding)
- Wikipedia: Integer overflow (unsigned wrap-around, carry flag versus overflow flag)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.