Chapterبەش 4 · Lectureوانە 4.1
Binary Coded Decimal (BCD)کۆدی دەیی دووانی
The 8421 BCD code: each decimal digit as its own 4-bit group, the six invalid codes, why BCD is not binary, converting both ways, and BCD addition with the full correction rule (add 6 when a group is above 9 or gives a carry), worked on and .
8421: هەر وەک کۆمەڵەیەکی 4 بیتیی خۆی، شەش کۆدە نادروستەکە، بۆچی نییە، گۆڕین بۆ هەردوو لا و کۆکردنەوەی بە یاسای تەواوی ڕاستکردنەوە (6 زیاد بکە کاتێک کۆمەڵەیەک لە 9 گەورەتر بێت یان بدات)، لەسەر و شیکراوەتەوە.
What you will learnچی فێر دەبیت
- Convert decimal numbers to BCD and BCD codes to decimal.
- Recognise the six invalid codes and explain why BCD differs from binary.
- Add BCD numbers and apply the correction in both cases (sum above 9, or a carry out).
- Convert between BCD and Excess-3, and explain why Excess-3 is self-complementing.
- ژمارەی بگۆڕیت بۆ و ژمارەکانی بۆ .
- شەش کۆدە نادروستەکە بناسیتەوە و ڕوون بکەیتەوە بۆچی لە جیاوازە.
- ژمارەکانی کۆ بکەیتەوە و ڕاستکردنەوەی لە هەردوو حاڵەتدا بەکار بهێنیت (کۆی سەروو 9، یان دەرەوە).
- و Excess-3 بۆ یەکتر بگۆڕیت و ڕوون بکەیتەوە بۆچی Excess-3 خۆتەواوکەرە.
Each decimal digit in its own 4 bitsهەر تاکژمارەیەکی دەیی لە 4 بیتی خۆیدا
Binary is perfect for a computer, but people think in decimal. Devices that show numbers to people — a calculator, a digital clock, a petrol-pump display — often keep each decimal digit separately. That is BCD, Binary Coded Decimal: each digit 0–9 is written as its own group of 4 bits.
بۆ تەواوە، بەڵام مرۆڤ بە بیر دەکاتەوە. ئەو ئامێرانەی ژمارە بە مرۆڤ پیشان دەدەن — ، کاتژمێری ، شاشەی بەنزینخانە — زۆرجار هەر بە جیا هەڵدەگرن. ئەمە ـە (Binary Coded Decimal): هەر لە 0 تا 9 وەک کۆمەڵەیەکی 4 بیتیی خۆی دەنووسرێت.
A code that writes each decimal digit separately as its own 4-bit group, with the weights 8, 4, 2, 1. The groups 1010 to 1111 are not used.
کۆدێکە کە هەر بە جیا وەک کۆمەڵەیەکی 4 بیتی دەنووسێت، بە کێشەکانی 8، 4، 2 و 1. کۆمەڵەکانی 1010 تا 1111 بەکار ناهێنرێن.
The four bits have the weights 8, 4, 2, 1 (), so this code is also called 8421 BCD. A group of 4 bits is called a .
چوار 8، 4، 2، 1یان هەیە ()، بۆیە بەم کۆدە دەڵێن 8421 BCD. کۆمەڵەیەکی 4 بیتی پێی دەڵێن .
| Decimal digit | 8 | 4 | 2 | 1 | BCD |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0000 |
| 1 | 0 | 0 | 0 | 1 | 0001 |
| 2 | 0 | 0 | 1 | 0 | 0010 |
| 3 | 0 | 0 | 1 | 1 | 0011 |
| 4 | 0 | 1 | 0 | 0 | 0100 |
| 5 | 0 | 1 | 0 | 1 | 0101 |
| 6 | 0 | 1 | 1 | 0 | 0110 |
| 7 | 0 | 1 | 1 | 1 | 0111 |
| 8 | 1 | 0 | 0 | 0 | 1000 |
| 9 | 1 | 0 | 0 | 1 | 1001 |
The digital clock on a tea-house wall shows 12:47 with four separate digit panels. Each panel needs only to know its own digit, 0 to 9. BCD stores numbers the same way: one small 4-bit group per panel.
کاتژمێرە دیواری چایخانەیەک 12:47 بە چوار پانێڵی جیا پیشان دەدات. هەر پانێڵێک تەنها پێویستە خۆی بزانێت، لە 0 تا 9. ژمارە بە هەمان شێوە هەڵدەگرێت: بۆ هەر پانێڵێک کۆمەڵەیەکی بچووکی 4 بیتی.
Where the analogy stops workingسنووری ئەم نموونەیە
A clock never does arithmetic beyond adding one minute. When BCD numbers are added, the groups need a correction step that plain binary does not need (later in this lesson).
کاتژمێر جگە لە زیادکردنی خولەکێک هیچ ژمێرکارییەک ناکات. کاتێک ژمارەکانی کۆ دەکرێنەوە، کۆمەڵەکان پێویستیان بە هەنگاوێکی ڕاستکردنەوە هەیە کە سادە پێویستی پێی نییە (دواتر لەم وانەیەدا).
Six codes are never usedشەش کۆد هەرگیز بەکار نایەن
Four bits give 16 patterns, but there are only ten decimal digits. The six patterns 1010, 1011, 1100, 1101, 1110 and 1111 (10 to 15) are invalid in 8421 BCD. If one of them appears, something went wrong — for example an addition that still needs correcting.
چوار 16 پێکهاتە دەدەن، بەڵام تەنها دە هەیە. شەش پێکهاتەی 1010، 1011، 1100، 1101، 1110 و 1111 (10 تا 15) لە 8421دا نادروستن. ئەگەر یەکێکیان دەرکەوت، شتێک هەڵەیە — بۆ نموونە کۆکردنەوەیەک کە هێشتا پێویستی بە ڕاستکردنەوە هەیە.
Decimal to BCDلە دەییەوە بۆ کۆدی دەیی دووانی
Replace every decimal digit with its 4-bit code, and keep the groups in the same order. No division is needed.
هەر بە کۆدە 4 بیتییەکەی بگۆڕە و کۆمەڵەکان بە هەمان ڕیز بهێڵەوە. هیچ دابەشکردنێک پێویست نییە.
- 24 → 2 =
0010, 4 =0100→0010 0100 - 278 →
0010 0111 1000
- 24: 2 =
0010، 4 =0100، کەواتە دەبێتە0010 0100 - 278 دەبێتە
0010 0111 1000
Converting decimal numbers to BCD digit by digit with the 8421 weights, with several worked examples.
گۆڕینی ژمارەی بۆ ، بە ، بە 8421، لەگەڵ چەند نموونەیەکی شیکراوە.
Whole video (5:38).
هەموو ڤیدیۆکە (5:38).
BCD is not binaryکۆدی دەیی دووانی دووانی نییە
The same decimal number gives different bits in BCD and in binary. 37 in BCD is 0011 0111. 37 in binary is 100101 (). If you read the BCD bits as one binary number, you get 55, not 37.
هەمان ژمارەی لە و لە جیاواز دەدات. 37 بە دەکاتە 0011 0111. 37 بە دەکاتە 100101 (). ئەگەر وەک یەک ژمارەی بخوێنیتەوە، 55 دەردەچێت نەک 37.
BCD also needs more bits. 278 takes 12 bits in BCD but only 9 bits in binary (100010110), because BCD uses only 10 of the 16 patterns of every group.
زیاتریشی پێویستە. 278 بە 12 دەگرێت، بەڵام بە تەنها 9 (100010110)، چونکە لە هەر کۆمەڵەیەکدا تەنها 10 لە 16 پێکهاتەکە بەکار دەهێنێت.
BCD is not binaryکۆدی دەیی دووانی دووانی نییە
Binary to BCD and back: go through decimalلە دووانییەوە بۆ کۆدی دەیی دووانی و بە پێچەوانەوە: بە دەییدا تێپەڕە
Binary and BCD follow different rules, so you cannot just regroup the bits. Go through decimal in two steps:
و یاسای جیاوازیان هەیە، بۆیە ناتوانیت تەنها دووبارە کۆمەڵە بکەیتەوە. بە دوو هەنگاو بە تێپەڕە:
- Binary → decimalدووانی ← دەیی
11101= .11101= . - Decimal → BCDدەیی ← کۆدی دەیی دووانی
2 =
0010and 9 =1001, so 29 is0010 1001in BCD.2 =
0010و 9 =1001، بۆیە 29 بە دەبێتە0010 1001. - And backگەڕانەوە
0010 1001→ digits 2 and 9 → 29 → divide by 2 again and again (Decimal to binary) →11101.0010 1001← 2 و 9 ← 29 ← چەند جار دابەشی 2 بکە (لە دەییەوە بۆ دووانی) ←11101.
BCD to decimalلە کۆدی دەیی دووانییەوە بۆ دەیی
Start at the rightmost bit.
لە لای ڕاستترین دەست پێ بکە.
Split the code into groups of 4 bits, moving left. If the last group is short, add zeros on its left.
کۆدەکە بەرەو چەپ بکە بە کۆمەڵەی 4 بیتی. ئەگەر دوایین کۆمەڵە کورت بوو، سفری بۆ لای چەپی زیاد بکە.
Write the decimal digit of each group. (A group from 1010 to 1111 means the code is invalid.)
هەر کۆمەڵەیەک بنووسە. (کۆمەڵەیەک لە 1010 تا 1111 واتە کۆدەکە نادروستە.)
| BCD code | Groupsکۆمەڵەکان | Digits | Decimal | (Same number in binary)(هەمان ژمارە بە ) |
|---|---|---|---|---|
01000010 | 0100 0010 | 4 2 | 42 | 101010 |
000101100010 | 0001 0110 0010 | 1 6 2 | 162 | 10100010 |
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
Add BCD numbers one 4-bit group at a time, from the right, with ordinary binary addition. Then check each group's sum:
ژمارەکانی کۆمەڵە بە کۆمەڵە لە ڕاستەوە بە ئاسایی کۆ بکەرەوە. پاشان کۆی هەر کۆمەڵەیەک بپشکنە:
- Sum 9 or less, and no carry out of the group: the group is a valid digit. Leave it.
- Sum greater than 9 (
1010–1111) or a carry came out of the group: add0110(6) to the group. The carry from this correction goes to the next group on the left.
- کۆکە 9 یان کەمتر بێت و هیچ لە کۆمەڵەکە دەرنەچێت: کۆمەڵەکە دروستە. وازی لێ بهێنە.
- کۆکە لە 9 گەورەتر بێت (
1010–1111) یان لە کۆمەڵەکە دەرچووبێت:0110(6) بخە سەر کۆمەڵەکە. ئەم ڕاستکردنەوەیە دەچێتە کۆمەڵەی دواتری لای چەپ.
: 1011 is one of the invalid codes, so add 0110: 1011 + 0110 = 1 0001. The carry becomes the tens digit: 0001 0001 = 11.
: 1011 یەکێکە لە کۆدە نادروستەکان، بۆیە 0110 زیاد بکە: 1011 + 0110 = 1 0001. دەبێتە دەیان: 0001 0001 = 11.
Adding BCD numbers: why a 4-bit sum above 9 is invalid and how adding 0110 corrects it, ending with 789 + 123.
کۆکردنەوەی ژمارەکانی : بۆچی کۆیەکی 4 کە لە 9 گەورەتر بێت نادروستە و چۆن زیادکردنی 0110 ڕاستی دەکاتەوە، لە کۆتاییدا .
From 1:45 (BCD addition); the first 1:45 is a recap of binary codes.
لە 1:45ـەوە (کۆکردنەوەی )؛ 1:45 خولەکی یەکەم پێداچوونەوەیەکی کۆدەکانی .
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
Why add 6?بۆچی 6 زیاد دەکەین؟
A 4-bit group counts up to 15 before it carries — it has 16 patterns. A decimal digit must carry at 10. The difference is : the six unused patterns. Adding 6 makes the group jump over them, so it carries exactly when a decimal digit should.
کۆمەڵەیەکی 4 بیتی تا 15 دەژمێرێت پێش ئەوەی بدات — 16 پێکهاتەی هەیە. دەبێت لە 10دا بدات. جیاوازییەکە ـە: شەش پێکهاتە بەکارنەهاتووەکە. زیادکردنی 6 وا دەکات کۆمەڵەکە بەسەریاندا باز بدات، بۆیە ڕێک ئەو کاتە دەدات کە دەبێت بیدات.
- Sum 10–15: gives 16–21, which carries out and leaves the right digit ( → carry, digit 1).
- Sum 16–19: the carry already left, but it took away 16 instead of 10, so the group is 6 short. puts back the missing 6 (18: group
0010+0110=1000= 8).
- کۆی 10–15: دەبێتە 16–21 کە دەدات و دروست بەجێ دەهێڵێت ( ← ، 1).
- کۆی 16–19: پێشتر دەرچووە، بەڵام لە جیاتی 10، 16ـی بردووە، بۆیە کۆمەڵەکە 6 کەمە. ئەو 6ـە ونبووە دەگەڕێنێتەوە (18: کۆمەڵەی
0010+0110=1000= 8).
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
The case the slide forgot: ئەو حاڵەتەی سلایدەکە لەبیری کرد:
= 1 0010. The group shows 0010, which looks like a valid 2 — but a carry came out, so it is wrong. Add 0110: 0010 + 0110 = 1000 = 8, and the carry is the tens digit 1. Answer: 0001 1000 = 18.
= 1 0010. کۆمەڵەکە 0010 پیشان دەدات کە وەک 2ێکی دروست دیارە — بەڵام دەرچووە، بۆیە هەڵەیە. 0110 زیاد بکە: 0010 + 0110 = 1000 = 8 و دەیانە: 1. وەڵام: 0001 1000 = 18.
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
Worked example: نموونەی شیکراوە:


- Write both numbers in BCDهەردوو ژمارەکە بە کۆدی دەیی دووانی بنووسە
59 =
0101 1001, 39 =0011 1001.59 =
0101 1001، 39 =0011 1001. - Units groupکۆمەڵەی یەکان
1001+1001=1 0010(18). A carry came out → add0110:0010+0110=1000(8). Carry 1 to the tens.1001+1001=1 0010(18). دەرچوو ←0110زیاد بکە:0010+0110=1000(8). 1 بگوازەرەوە بۆ دەیان. - Tens groupکۆمەڵەی دەیان
0101+0011+1=1001(9). Not above 9 and no carry: valid.0101+0011+1=1001(9). لە 9 گەورەتر نییە و نییە: دروستە. - Answerوەڵام
1001 1000= 98. ✓1001 1000= 98. ✓
The slide adds all 8 bits at once (01011001 + 00111001 = 10010010); the carry from the units then flows into the tens by itself. It then adds 0110 to the units group, which gave a carry, and reaches the same 1001 1000.
سلایدەکە هەر 8 پێکەوە کۆ دەکاتەوە (01011001 + 00111001 = 10010010)؛ ئەو کاتە یەکان خۆی دەچێتە ناو دەیان. پاشان 0110 دەخاتە سەر کۆمەڵەی یەکان کە دابوو و دەگاتە هەمان 1001 1000.
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
Exam example: نموونەی تاقیکردنەوە:
A midterm asked: convert each number to BCD and add, . Two of the three groups need correcting, one for each case of the rule.
تاقیکردنەوەی نیوەی وەرز داوای کرد: هەر ژمارەیەک بگۆڕە بۆ و کۆیان بکەرەوە، . دوو لە سێ کۆمەڵەکە پێویستیان بە ڕاستکردنەوە هەیە، هەریەکەیان بۆ حاڵەتێکی یاساکە.
- Write both numbers in BCDهەردوو ژمارەکە بە کۆدی دەیی دووانی بنووسە
396 =
0011 1001 0110, 275 =0010 0111 0101.396 =
0011 1001 0110، 275 =0010 0111 0101. - Units: یەکان:
0110+0101=1011(11) → greater than 9 → +0110=1 0001: digit0001, carry 1.0110+0101=1011(11) ← لە 9 گەورەترە ← +0110=1 0001:0001، 1. - Tens: دەیان:
1001+0111+1=1 0001(17) → a carry came out → +0110:0001+0110=0111: digit 7, carry 1.1001+0111+1=1 0001(17) ← دەرچوو ← +0110:0001+0110=0111: 7، 1. - Hundreds: سەدان:
0011+0010+1=0110(6) → valid.0011+0010+1=0110(6) ← دروستە. - Answerوەڵام
0110 0111 0001= 671. ✓ ()0110 0111 0001= 671. ✓ ()
Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی
How the exam paper did itپەڕەی تاقیکردنەوەکە چۆن کردی
Other decimal codesکۆدە دەییەکانی تر
8421 BCD is the best-known way to write decimal digits in bits, but not the only one. Codes for digits and characters fall into a few families. The last column shows the digit 5 in each code:
8421 ناسراوترین ڕێگای نووسینی بە ، بەڵام تاکە ڕێگا نییە. کۆدەکانی و پیتەکان دەبنە چەند خێزانێک. ستوونی کۆتایی 5 لە هەر کۆدێکدا پیشان دەدات:
| Familyخێزان | Examplesنموونە | The digit 5 5 |
|---|---|---|
| Weighted: every position has a weightکێشدار: هەر شوێنێک کێشێکی هەیە | 8421 BCD, 2421, 8421، 2421، | 0101, 1011, 10110101، 1011، 1011 |
| Non-weighted: no position weightsبێکێش: شوێنەکان کێشیان نییە | Excess-3, Gray codeExcess-3، کۆدی گرەی | 1000, 01111000، 0111 |
| Alphanumeric: letters and symbols tooپیت و ژمارە: پیت و هێماکانیش | ASCII, EBCDIC, BaudotASCII، EBCDIC، Baudot | 0110101 in ASCII0110101 بە |
| Error-detecting: an extra check bitدۆزینەوەی هەڵە: پشکنینی زیادە | a parity bit added to any codeبیتی پاریتی کە دەخرێتە سەر هەر کۆدێک | 0101 + an even-parity bit 00101 و 0 (جووت) |
In a weighted code you add the weights of the 1 bits: in 2421, 1011 is ; in , 1011 is . A non-weighted code has no position weights, so you read it from its table.
لە کۆدێکی کێشداردا کێشی 1 کۆ دەکەیتەوە: لە 2421ـدا 1011 دەکاتە ؛ لە ـدا 1011 دەکاتە . کۆدێکی بێکێش کێشی شوێنەکانی نییە، بۆیە لە خشتەکەیەوە دەیخوێنیتەوە.
Other decimal codesکۆدە دەییەکانی تر
Excess-3: BCD plus threeExcess-3: کۆدی دەیی دووانی زیاد سێ
Excess-3 (XS-3) is a non-weighted code for decimal digits. Each digit is written as its 8421 code plus 3 (0011). So 0 becomes 0011 and 9 becomes 1100. The six unused patterns are 0000, 0001, 0010, 1101, 1110 and 1111.
Excess-3 (XS-3) کۆدێکی بێکێشە بۆ . هەر بە کۆدی 8421ـەکەی زیاد 3 (0011) دەنووسرێت. بۆیە 0 دەبێتە 0011 و 9 دەبێتە 1100. شەش پێکهاتە بەکارنەهاتووەکە 0000، 0001، 0010، 1101، 1110 و 1111ن.
| Decimal digit | 8421 BCD 8421 | Excess-3کۆدی Excess-3 |
|---|---|---|
| 0 | 0000 | 0011 |
| 1 | 0001 | 0100 |
| 2 | 0010 | 0101 |
| 3 | 0011 | 0110 |
| 4 | 0100 | 0111 |
| 5 | 0101 | 1000 |
| 6 | 0110 | 1001 |
| 7 | 0111 | 1010 |
| 8 | 1000 | 1011 |
| 9 | 1001 | 1100 |
Other decimal codesکۆدە دەییەکانی تر
BCD ⇄ Excess-3, digit by digitکۆدی دەیی دووانی ⇄ Excess-3، تاکژمارە بە تاکژمارە
- BCD → Excess-3: add
0011to every 4-bit group. 29 =0010 1001in BCD →0101 1100in Excess-3. - Excess-3 → BCD: subtract
0011from every group.1001 1010→0110 0111= 67.
- ← Excess-3:
0011بخە سەر هەموو کۆمەڵەیەکی 4 بیتی. 29 بە0010 1001ـە ← بە Excess-3 دەبێتە0101 1100. - Excess-3 ← :
0011لە هەموو کۆمەڵەیەک دەربکە.1001 1010←0110 0111= 67.
Other decimal codesکۆدە دەییەکانی تر
Why Excess-3? Flip the bits, get the 9's complementبۆچی Excess-3؟ بیتەکان پێچەوانە بکەرەوە، تەواوکەری نۆ وەربگرە
Invert the bits of an Excess-3 digit and you get the Excess-3 code of 9 minus that digit: 7 = 1010 → inverted 0101 = 2, and . That is the 9's complement, the decimal way to subtract by adding (9's and 10's complements). A code like this is called self-complementing. 8421 BCD is not: inverting 7 (0111) gives 1000 = 8.
Excess-3 پێچەوانە بکەرەوە، کۆدی Excess-3ـی 9 کەم ئەو وەردەگریت: 7 = 1010 ← پێچەوانەکراوەکەی 0101 = 2 و . ئەمە تەواوکەری نۆیە، ڕێگای بۆ لێدەرکردن بە کۆکردنەوە (تەواوکەری نۆ و دە). کۆدێکی وا پێی دەڵێن خۆتەواوکەر. 8421 وا نییە: پێچەوانەکردنەوەی 7 (0111) 1000 دەدات کە 8ـە.
| Numberژمارە | Excess-3کۆدی Excess-3 |
|---|---|
| 274 | 0101 1010 0111 |
| 725 (bits inverted)725 ( پێچەوانەکراو) | 1010 0101 1000 |
George Stibitz used Excess-3 in the relay adding machine he built in 1937. It was later used in some early computers, cash registers and 1970s pocket calculators. The weighted codes 2421 and are self-complementing too.
جۆرج ستیبیتز Excess-3ـی لەو ئامێرە کۆکەرەوە ڕیلەییەدا بەکار هێنا کە لە 1937 دروستی کرد. دواتر لە هەندێک سەرەتایی، مەکینەی پارەی دوکان و گیرفانی ساڵانی حەفتاکاندا بەکار هات. کۆدە کێشدارەکانی 2421 و یش خۆتەواوکەرن.
Exercisesڕاهێنانەکان
Add the BCD numbers: (a) 0011 + 0100 (b) 00100011 + 00010101 (c) 10000110 + 00010011 (d) 010001010000 + 010000010111.
ژمارەکانی کۆ بکەرەوە: (أ) 0011 + 0100 (ب) 00100011 + 00010101 (ج) 10000110 + 00010011 (د) 010001010000 + 010000010111.
Hintئاماژە
Split each number into 4-bit groups from the right first.
سەرەتا هەر ژمارەیەک لە ڕاستەوە بکە بە کۆمەڵەی 4 بیتی.
Show answerوەڵامەکە پیشان بدە
| # | BCD sumکۆکردنەوەی | Decimal | Workingهەژمار | Answerوەڵام |
|---|---|---|---|---|
| (a)(أ) | 0011 + 0100 | no correctionبێ ڕاستکردنەوە | 0111 = 7 | |
| (b)(ب) | 0010 0011 + 0001 0101 | no correctionبێ ڕاستکردنەوە | 0011 1000 = 38 | |
| (c)(ج) | 1000 0110 + 0001 0011 | no correctionبێ ڕاستکردنەوە | 1001 1001 = 99 | |
| (d)(د) | 0100 0101 0000 + 0100 0001 0111 | no correctionبێ ڕاستکردنەوە | 1000 0110 0111 = 867 |
Every group sum is 9 or less with no carry, so no group needs .
کۆی هەموو کۆمەڵەیەک 9 یان کەمترە و نییە، بۆیە هیچ کۆمەڵەیەک پێویستی بە نییە.
Add the BCD numbers: (a) 1001 + 0100 (b) 1001 + 1001 (c) 01100111 + 01010011 (d) 00010110 + 00010101.
ژمارەکانی کۆ بکەرەوە: (أ) 1001 + 0100 (ب) 1001 + 1001 (ج) 01100111 + 01010011 (د) 00010110 + 00010101.
Hintئاماژە
Check every group: above 9, or a carry out → add 0110.
هەموو کۆمەڵەیەک بپشکنە: لە 9 گەورەتر، یان دەرەوە ← 0110 زیاد بکە.
Show answerوەڵامەکە پیشان بدە
| # | BCD sumکۆکردنەوەی | Decimal | Workingهەژمار | Answerوەڵام |
|---|---|---|---|---|
| (a)(أ) | 1001 + 0100 | 1101 > 9 → +0110 = 1 00111101 > 9 ← +0110 = 1 0011 | 0001 0011 = 13 | |
| (b)(ب) | 1001 + 1001 | 1 0010: carry → +0110 → 10001 0010: ← +0110 ← 1000 | 0001 1000 = 18 | |
| (c)(ج) | 0110 0111 + 0101 0011 | units 1010 > 9 → 0000, carry; tens = 1100 > 9 → 0010, carryیەکان 1010 > 9 ← 0000، ؛ دەیان = 1100 > 9 ← 0010، | 0001 0010 0000 = 120 | |
| (d)(د) | 0001 0110 + 0001 0101 | units 1011 > 9 → 0001, carry; tens = 0011یەکان 1011 > 9 ← 0001، ؛ دەیان = 0011 | 0011 0001 = 31 |
Convert to BCD and add: (a) (b) .
بیانگۆڕە بۆ و کۆیان بکەرەوە: (أ) (ب) .
Show answerوەڵامەکە پیشان بدە
- (a)
0100 0111+0011 1000: units0111+1000=1111= → +0110=1 0101: digit 5, carry 1; tens =1000. Answer1000 0101= 85. - (b)
0010 1000+0001 0101: units1000+0101=1101= → +0110=1 0011: digit 3, carry 1; tens =0100. Answer0100 0011= 43.
- (أ)
0100 0111+0011 1000: یەکان0111+1000=1111= ← +0110=1 0101: 5، 1؛ دەیان =1000. وەڵام1000 0101= 85. - (ب)
0010 1000+0001 0101: یەکان1000+0101=1101= ← +0110=1 0011: 3، 1؛ دەیان =0100. وەڵام0100 0011= 43.
A 12-bit register holds 0100 1000 0110. What number is it (a) in 8421 BCD, (b) in Excess-3, (c) as plain binary?
12 بیتی 0100 1000 0110 هەڵدەگرێت. ئەمە کام ژمارەیە (أ) بە 8421، (ب) بە Excess-3، (ج) وەک سادە؟
Hintئاماژە
For the two decimal codes, read each 4-bit group on its own.
بۆ دوو کۆدە ، هەر کۆمەڵەیەکی 4 بیتی بە جیا بخوێنەرەوە.
Show answerوەڵامەکە پیشان بدە
- (a) BCD: 4, 8, 6 → 486.
- (b) Excess-3: subtract 3 from each group: 1, 5, 3 → 153.
- (c) Binary: = 1158. The bits alone do not tell you the number; you must know the code.
- (أ) : 4، 8، 6 ← 486.
- (ب) Excess-3: 3 لە هەر کۆمەڵەیەک دەربکە: 1، 5، 3 ← 153.
- (ج) : = 1158. بە تەنها ژمارەکە ناڵێن؛ دەبێت کۆدەکە بزانیت.
Where BCD is used todayکۆدی دەیی دووانی ئەمڕۆ لە کوێ بەکار دێت
- Calculators, clocks and displays. Each digit drives its own display, and a digital clock keeps the time as BCD digits. Many real-time clock chips in computers still store the time and date in BCD.
- Money. A decimal amount such as 0.10 cannot be stored exactly in binary, but decimal digits can. Banking and business software often uses decimal arithmetic for that reason.
- Processors. Intel x86 processors have a DAA (decimal adjust after addition) instruction. It adds 6 to the low group when it is above 9 or a carry came out of it — the corrected rule of this lesson. (It does not exist in 64-bit mode.)
- Packed and unpacked. Packed BCD puts two digits in one byte (91 =
1001 0001); unpacked BCD uses a whole byte per digit (91 =00001001 00000001).
- ، کاتژمێر و شاشە. هەر شاشەی خۆی هەیە و کاتژمێری کات وەک هەڵدەگرێت. زۆرێک لە کاتژمێری ناو هێشتا کات و ڕێکەوت بە هەڵدەگرن.
- پارە. بڕێکی وەک 0.10 بە بە تەواوی هەڵناگیرێت، بەڵام هەڵدەگیرێن. بۆیە بانک و بازرگانی زۆرجار ژمێرکاریی بەکار دەهێنێت.
- پرۆسێسەر. پرۆسێسەرەکانی Intel x86 DAA (decimal adjust after addition)یان هەیە. 6 دەخاتە سەر کۆمەڵەی خوارەوە کاتێک لە 9 گەورەتر بێت یان لێی دەرچووبێت — ڕێک یاسا ڕاستکراوەکەی ئەم وانەیە. (لە دۆخی 64 بیتیدا بوونی نییە.)
- Packed و unpacked. packed دوو لە یەک دادەنێت (91 =
1001 0001)؛ unpacked بۆ هەر تەواو بەکار دەهێنێت (91 =00001001 00000001).
Where BCD is still used: real-time clock chips and the timers and counters of factory PLCs.
هێشتا لە کوێ بەکار دێت: کاتژمێری (RTC) و و PLCـی کارگەکان.
From 7:19: real-time clock (RTC) chips, then PLC timers and counters.
لە 7:19ـەوە: کاتژمێری (RTC)، پاشان و PLC.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Fixچارەسەر |
|---|---|
Converting the whole number to binary (37 → 100101).گۆڕینی هەموو ژمارەکە بۆ (37 ← 100101). | BCD converts digit by digit: 37 → 0011 0111. بە دەگۆڕێت: 37 ← 0011 0111. |
Correcting only sums above 9 and forgetting the carry case ( → 0010).تەنها ڕاستکردنەوەی کۆی سەروو 9 و لەبیرکردنی حاڵەتی ( ← 0010). | Add 0110 when the group sum is above 9 or a carry came out.0110 زیاد بکە کاتێک کۆی کۆمەڵە لە 9 گەورەتر بێت یان دەرچووبێت. |
Deciding all corrections from the first sum only. : 1001 1001 + 0000 0001 = 1001 1010; correcting only the units gives 1010 0000, still invalid.بڕیاردانی هەموو ڕاستکردنەوەکان تەنها لە کۆی یەکەمەوە. : 1001 1001 + 0000 0001 = 1001 1010؛ ڕاستکردنەوەی تەنها یەکان 1010 0000 دەدات کە هێشتا نادروستە. | Work right to left and check each group after its incoming carry: = 0001 0000 0000 = 100.لە ڕاستەوە بۆ چەپ کار بکە و هەر کۆمەڵەیەک دوای ئەوەی پێی گەیشت بپشکنە: = 0001 0000 0000 = 100. |
Grouping a BCD code from the left (1100101 → 1100 101).کۆمەڵەکردنی ژمارەیەکی لە چەپەوە (1100101 ← 1100 101). | Group from the right and pad on the left: 0110 0101 = 65.لە ڕاستەوە کۆمەڵە بکە و سفر بخە لای چەپ: 0110 0101 = 65. |
| Dropping the carry out of the leftmost group.فڕێدانی چەپترین کۆمەڵە. | In BCD that carry is a new digit: = 0001 1000, not 1000.لە ئەو نوێیە: = 0001 1000، نەک 1000. |
Summaryپوختە
- BCD writes each decimal digit as its own 4-bit group with weights 8, 4, 2, 1.
1010to1111are invalid; only 10 of the 16 patterns are used.- BCD is not binary: 37 =
0011 0111in BCD but100101in binary. - BCD → decimal: group by 4 from the right, then read each digit.
- BCD addition: add group by group from the right; if a group sum is above 9 or a carry comes out, add
0110. - Excess-3 = each digit's BCD +
0011(digit by digit). It is self-complementing: inverting the bits gives the 9's complement.
- هەر وەک کۆمەڵەیەکی 4 بیتیی خۆی بە 8، 4، 2، 1 دەنووسێت.
1010تا1111نادروستن؛ تەنها 10 لە 16 پێکهاتەکە بەکار دێن.- نییە: 37 بە
0011 0111ـە بەڵام بە100101. - ← : لە ڕاستەوە 4 بە 4 کۆمەڵە بکە، پاشان هەر بخوێنەرەوە.
- کۆکردنەوەی : کۆمەڵە بە کۆمەڵە لە ڕاستەوە کۆ بکەرەوە؛ ئەگەر کۆی کۆمەڵەیەک لە 9 گەورەتر بوو یان دەرچوو،
0110زیاد بکە. - Excess-3 = هەر +
0011( بە ). خۆتەواوکەرە: پێچەوانەکردنەوەی تەواوکەری نۆ دەدات.
Why is the tricky case?بۆچی حاڵەتە فێڵاوییەکەیە؟
Its group shows 0010, which looks valid; only the carry shows that 6 must be added.
کۆمەڵەکەی 0010 پیشان دەدات کە دروست دیارە؛ تەنها پیشان دەدات کە دەبێت 6 زیاد بکرێت.
How many bits does 2026 need in BCD?2026 بە کۆدی دەیی دووانی چەند بیتی دەوێت؟
16: four digits × 4 bits = 0010 0000 0010 0110.
16: چوار × 4 = 0010 0000 0010 0110.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
What BCD is, why 42 in BCD differs from 42 in binary, why printing numbers favoured BCD, and where BCD is still used.
چییە، بۆچی 42 بەو کۆدە جیاوازە لە 42 بە ، بۆچی بۆ چاپکردنی ژمارەکان باشتر بوو و هێشتا لە کوێ بەکار دێت.
0:20 what BCD is; 2:12 42 in binary; 3:09 the printable form of 42; 12:45 things that use BCD; 13:22 digital clocks.
0:20 چییە؛ 2:12 ژمارە 42 بە ؛ 3:09 شێوەی چاپکردنی 42؛ 12:45 ئەو شتانەی بەکار دەهێنن؛ 13:22 کاتژمێری .
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
The Gray Codeکۆدی گرەی
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.