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 59+3959 + 39 and 396+275396 + 275.

⁦8421⁩: هەر وەک کۆمەڵەیەکی 4 بیتیی خۆی، شەش کۆدە نادروستەکە، بۆچی نییە، گۆڕین بۆ هەردوو لا و کۆکردنەوەی بە یاسای تەواوی ڕاستکردنەوە (⁦6⁩ زیاد بکە کاتێک کۆمەڵەیەک لە 9 گەورەتر بێت یان بدات)، لەسەر 59+3959 + 39 و 396+275396 + 275 شیکراوەتەوە.

17 min read19 خولەک خوێندنەوە · 21 stepsهەنگاو

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 +6+6 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.
  • ژمارەی بگۆڕیت بۆ و ژمارەکانی بۆ .
  • شەش کۆدە نادروستەکە بناسیتەوە و ڕوون بکەیتەوە بۆچی لە جیاوازە.
  • ژمارەکانی کۆ بکەیتەوە و ڕاستکردنەوەی +6+6 لە هەردوو حاڵەتدا بەکار بهێنیت (کۆی سەروو 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 بیتیی خۆی دەنووسرێت.

Definitionپێناسە

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 (23,22,21,202^3, 2^2, 2^1, 2^0), so this code is also called 8421 BCD. A group of 4 bits is called a .

چوار 8، 4، 2، 1یان هەیە (23,22,21,202^3, 2^2, 2^1, 2^0)، بۆیە بەم کۆدە دەڵێن ⁦8421 BCD⁩. کۆمەڵەیەکی 4 بیتی پێی دەڵێن .

The ten BCD codesدە پێکهاتەکەی
Decimal digit 8421BCD
000000000
100010001
200100010
300110011
401000100
501010101
601100110
701110111
810001000
910011001
The clock on the tea-house wallکاتژمێرەکەی دیواری چایخانە

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).

کاتژمێر جگە لە زیادکردنی خولەکێک هیچ ژمێرکارییەک ناکات. کاتێک ژمارەکانی کۆ دەکرێنەوە، کۆمەڵەکان پێویستیان بە هەنگاوێکی ڕاستکردنەوە هەیە کە سادە پێویستی پێی نییە (دواتر لەم وانەیەدا).

Quick checkپشکنینی خێراWhat is the digit 7 in 8421 BCD? 7 بە ⁦8421⁩ چییە؟

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⁩دا نادروستن. ئەگەر یەکێکیان دەرکەوت، شتێک هەڵەیە — بۆ نموونە کۆکردنەوەیەک کە هێشتا پێویستی بە ڕاستکردنەوە هەیە.

Quick checkپشکنینی خێراIs 0101 1100 a valid BCD number?ئایا 0101 1100 ژمارەیەکی دروستی ؟

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
The digits 2, 7 and 8 each point down to their own 4-bit group, 0010, 0111 and 1000, with the weights 8 4 2 1 above every group. Below: (278)10 = 0010 0111 1000 (BCD).تاکژمارەکان 2، 7 و 8 هەریەکەیان ئاماژە بە کۆمەڵە 4 بیتییەکەی خۆی دەکات: 0010، 0111 و 1000. بەها خانەییەکان 8 4 2 1 لە سەر هەر کۆمەڵەیەکن. لە خوارەوە: (278)10 = 0010 0111 1000 (کۆدی دەیی دووانی).
278 in BCD: one 4-bit group per decimal digit.⁦278⁩ بە : بۆ هەر کۆمەڵەیەکی 4 بیتی.CêIT
Quick checkپشکنینی خێراWhat is 905 in BCD?⁦905⁩ بە چییە؟

Decimal to BCDThe Organic Chemistry Tutor · Englishئینگلیزی · 443K viewsبینین · 6.9K likesلایک

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 (32+4+132 + 4 + 1). If you read the BCD bits as one binary number, you get 55, not 37.

هەمان ژمارەی لە و لە جیاواز دەدات. ⁦37⁩ بە دەکاتە 0011 0111. ⁦37⁩ بە دەکاتە 100101 (32+4+132 + 4 + 1). ئەگەر وەک یەک ژمارەی بخوێنیتەوە، ⁦55⁩ دەردەچێت نەک ⁦37⁩.

Left: 37 in BCD, the digit 3 as 0011 and the digit 7 as 0111. Right: 37 in binary, 0010 0101 with the weights 128 to 1 (32 + 4 + 1). Below: the BCD bits 0011 0111 read as binary are 32 + 16 + 4 + 2 + 1 = 55.چەپ: 37 بە کۆدی دەیی دووانی، تاکژمارەکە 3 وەک 0011 و تاکژمارەکە 7 وەک 0111. ڕاست: 37 بە دووانی، 0010 0101 بە بەها خانەییەکان 128 تا 1 (32 + 4 + 1). خوارەوە: بیتەکانی کۆدی دەیی دووانیی 0011 0111 وەک دووانی دەکاتە 32 + 16 + 4 + 2 + 1 = 55.
37 in BCD and in binary.⁦37⁩ بە و بە .CêIT

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⁩ پێکهاتەکە بەکار دەهێنێت.

Quick checkپشکنینی خێراA register holds 0100 0101. As BCD it means 45. What does it mean as plain binary? 0100 0101 هەڵدەگرێت. وەک واتای ⁦45⁩ـە. وەک سادە چییە؟

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:

و یاسای جیاوازیان هەیە، بۆیە ناتوانیت تەنها دووبارە کۆمەڵە بکەیتەوە. بە دوو هەنگاو بە تێپەڕە:

  1. Binary → decimalدووانی ← دەیی

    11101 = 16+8+4+1=2916 + 8 + 4 + 1 = 29.

    11101 = 16+8+4+1=2916 + 8 + 4 + 1 = 29.

  2. Decimal → BCDدەیی ← کۆدی دەیی دووانی

    2 = 0010 and 9 = 1001, so 29 is 0010 1001 in BCD.

    2 = 0010 و 9 = 1001، بۆیە ⁦29⁩ بە دەبێتە 0010 1001.

  3. 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.

Quick checkپشکنینی خێراBinary 1010 is which BCD code? 1010 بە کام کۆدە؟

BCD to decimalلە کۆدی دەیی دووانییەوە بۆ دەیی

  1. Start at the rightmost bit.

    لە لای ڕاستترین دەست پێ بکە.

  2. Split the code into groups of 4 bits, moving left. If the last group is short, add zeros on its left.

    کۆدەکە بەرەو چەپ بکە بە کۆمەڵەی 4 بیتی. ئەگەر دوایین کۆمەڵە کورت بوو، سفری بۆ لای چەپی زیاد بکە.

  3. Write the decimal digit of each group. (A group from 1010 to 1111 means the code is invalid.)

    هەر کۆمەڵەیەک بنووسە. (کۆمەڵەیەک لە ⁦1010⁩ تا ⁦1111⁩ واتە کۆدەکە نادروستە.)

BCD codeGroupsکۆمەڵەکانDigitsDecimal(Same number in binary)(هەمان ژمارە بە )
010000100100 00104 242101010
0001011000100001 0110 00101 6 216210100010
Quick checkپشکنینی خێراWhat decimal number is the BCD code 1100101?ژمارەی 1100101 بە کام ژمارەی ؟

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: add 0110 (6) to the group. The carry from this correction goes to the next group on the left.
  • کۆکە 9 یان کەمتر بێت و هیچ لە کۆمەڵەکە دەرنەچێت: کۆمەڵەکە دروستە. وازی لێ بهێنە.
  • کۆکە لە 9 گەورەتر بێت (1010–1111) یان لە کۆمەڵەکە دەرچووبێت: 0110 ⁦(6)⁩ بخە سەر کۆمەڵەکە. ئەم ڕاستکردنەوەیە دەچێتە کۆمەڵەی دواتری لای چەپ.
0101+  01101011+  01101 0001\begin{array}{r}\mathtt{0101} \\ +\;\mathtt{0110} \\ \hline \mathtt{1011} \\ +\;\mathtt{0110} \\ \hline \mathtt{1\,0001}\end{array}

5+6=115 + 6 = 11: 1011 is one of the invalid codes, so add 0110: 1011 + 0110 = 1 0001. The carry becomes the tens digit: 0001 0001 = 11.

5+6=115 + 6 = 11: 1011 یەکێکە لە کۆدە نادروستەکان، بۆیە 0110 زیاد بکە: 1011 + 0110 = 1 0001. دەبێتە دەیان: 0001 0001 = ⁦11⁩.

Quick checkپشکنینی خێراWhich 4-bit group sums need the +6+6 correction?کۆی کام کۆمەڵە 4 بیتییانە پێویستیان بە ڕاستکردنەوەی +6+6 هەیە؟

BCD AdditionNeso Academy · Englishئینگلیزی · 162K viewsبینین · 2.9K likesلایک · Partبەشی 1:45–11:28 (ofلە 11:28)

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⁩ ڕاستی دەکاتەوە، لە کۆتاییدا 789+123789 + 123.

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 16−10=616 - 10 = 6: 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⁩دا بدات. جیاوازییەکە 16−10=616 - 10 = 6ـە: شەش پێکهاتە بەکارنەهاتووەکە. زیادکردنی 6 وا دەکات کۆمەڵەکە بەسەریاندا باز بدات، بۆیە ڕێک ئەو کاتە دەدات کە دەبێت بیدات.

  • Sum 10–15: +6+6 gives 16–21, which carries out and leaves the right digit (11+6=1711 + 6 = 17 → carry, digit 1).
  • Sum 16–19: the carry already left, but it took away 16 instead of 10, so the group is 6 short. +6+6 puts back the missing 6 (18: group 0010 + 0110 = 1000 = 8).
  • کۆی ⁦10–15⁩: +6+6 دەبێتە ⁦16–21⁩ کە دەدات و دروست بەجێ دەهێڵێت (11+6=1711 + 6 = 17 ← ، ⁦1⁩).
  • کۆی ⁦16–19⁩: پێشتر دەرچووە، بەڵام لە جیاتی ⁦10⁩، ⁦16⁩ـی بردووە، بۆیە کۆمەڵەکە 6 کەمە. +6+6 ئەو 6ـە ونبووە دەگەڕێنێتەوە (⁦18⁩: کۆمەڵەی 0010 + 0110 = 1000 = ⁦8⁩).
Quick checkپشکنینی خێراWhy exactly 6 and not some other number?بۆچی ڕێک 6 نەک ژمارەیەکی تر؟

Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی

The case the slide forgot: 9+99 + 9ئەو حاڵەتەی سلایدەکە لەبیری کرد: 9+99 + 9

1001+  10011 0010\begin{array}{r}\mathtt{1001} \\ +\;\mathtt{1001} \\ \hline \mathtt{1\,0010}\end{array}

9+9=189 + 9 = 18 = 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.

9+9=189 + 9 = 18 = 1 0010. کۆمەڵەکە 0010 پیشان دەدات کە وەک 2ێکی دروست دیارە — بەڵام دەرچووە، بۆیە هەڵەیە. 0110 زیاد بکە: 0010 + 0110 = 1000 = 8 و دەیانە: 1. وەڵام: 0001 1000 = ⁦18⁩.

Quick checkپشکنینی خێرا1000+10001000 + 1000 (8+88 + 8) in BCD gives 1 0000. What is the correct BCD answer?1000 + 1000 (8+88 + 8) بە 1 0000 دەدات. وەڵامی دروستی چییە؟

Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی

Worked example: 59+3959 + 39نموونەی شیکراوە: 59+3959 + 39

59 = 0101 1001 and 39 = 0011 1001 are written one under the other, tens and units in separate columns. The units add to 1 0010: a carry comes out, so 0110 is added and the units become 1000 with a carry of 1 to the tens. The tens add 0101 + 0011 + 1 = 1001. The answer 1001 1000 = 98 appears.
59 = 0101 1001 and 39 = 0011 1001 are written one under the other, tens and units in separate columns. The units add to 1 0010: a carry comes out, so 0110 is added and the units become 1000 with a carry of 1 to the tens. The tens add 0101 + 0011 + 1 = 1001. The answer 1001 1000 = 98 appears.
59+3959 + 39 in BCD: the units group needs the +6+6 correction because a carry came out.59+3959 + 39 بە : کۆمەڵەی یەکان پێویستی بە ڕاستکردنەوەی +6+6 هەیە چونکە دەرچووە.CêIT
  1. Write both numbers in BCDهەردوو ژمارەکە بە کۆدی دەیی دووانی بنووسە

    59 = 0101 1001, 39 = 0011 1001.

    ⁦59⁩ = 0101 1001، ⁦39⁩ = 0011 1001.

  2. Units groupکۆمەڵەی یەکان

    1001 + 1001 = 1 0010 (18). A carry came out → add 0110: 0010 + 0110 = 1000 (8). Carry 1 to the tens.

    1001 + 1001 = 1 0010 ⁦(18)⁩. دەرچوو ← 0110 زیاد بکە: 0010 + 0110 = 1000 ⁦(8). 1⁩ بگوازەرەوە بۆ دەیان.

  3. Tens groupکۆمەڵەی دەیان

    0101 + 0011 + 1 = 1001 (9). Not above 9 and no carry: valid.

    0101 + 0011 + 1 = 1001 ⁦(9)⁩. لە 9 گەورەتر نییە و نییە: دروستە.

  4. 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: 396+275396 + 275نموونەی تاقیکردنەوە: 396+275396 + 275

A midterm asked: convert each number to BCD and add, 396+275396 + 275. Two of the three groups need correcting, one for each case of the rule.

تاقیکردنەوەی نیوەی وەرز داوای کرد: هەر ژمارەیەک بگۆڕە بۆ و کۆیان بکەرەوە، 396+275396 + 275. دوو لە سێ کۆمەڵەکە پێویستیان بە ڕاستکردنەوە هەیە، هەریەکەیان بۆ حاڵەتێکی یاساکە.

  1. Write both numbers in BCDهەردوو ژمارەکە بە کۆدی دەیی دووانی بنووسە

    396 = 0011 1001 0110, 275 = 0010 0111 0101.

    ⁦396⁩ = 0011 1001 0110، ⁦275⁩ = 0010 0111 0101.

  2. Units: 6+56 + 5یەکان: 6+56 + 5

    0110 + 0101 = 1011 (11) → greater than 9 → + 0110 = 1 0001: digit 0001, carry 1.

    0110 + 0101 = 1011 ⁦(11)⁩ ← لە 9 گەورەترە ← + 0110 = 1 0001: 0001، 1.

  3. Tens: 9+7+19 + 7 + 1دەیان: 9+7+19 + 7 + 1

    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.

  4. Hundreds: 3+2+13 + 2 + 1سەدان: 3+2+13 + 2 + 1

    0011 + 0010 + 1 = 0110 (6) → valid.

    0011 + 0010 + 1 = 0110 ⁦(6)⁩ ← دروستە.

  5. Answerوەڵام

    0110 0111 0001 = 671. ✓ (396+275=671396 + 275 = 671)

    0110 0111 0001 = ⁦671⁩. ✓ (396+275=671396 + 275 = 671)

Quick checkپشکنینی خێراIn 396+275396 + 275, why does the tens group need +6+6 although its 4 bits read 0001 (a valid code)?لە 396+275396 + 275دا بۆچی کۆمەڵەی دەیان پێویستی بە +6+6 هەیە هەرچەندە 4 0001 (کۆدێکی دروست) دەخوێننەوە؟

Adding BCD numbersکۆکردنەوەی ژمارەکانی کۆدی دەیی دووانی

How the exam paper did itپەڕەی تاقیکردنەوەکە چۆن کردی

Quick checkپشکنینی خێراThe exam paper added 0011 1001 0110 + 0010 0111 0101 as one binary number and got 0110 0000 1011. Which groups then needed +6+6?پەڕەی تاقیکردنەوەکە 0011 1001 0110 + 0010 0111 0101ـی وەک یەک ژمارەی کۆ کردەوە و 0110 0000 1011ـی دەست کەوت. پاشان کام کۆمەڵانە پێویستیان بە +6+6 بوو؟

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 لە هەر کۆدێکدا پیشان دەدات:

Families of binary codesخێزانەکانی کۆدی
FamilyخێزانExamplesنموونەThe digit 5 5
Weighted: every position has a weightکێشدار: هەر شوێنێک کێشێکی هەیە8421 BCD, 2421, 8 4 −2 −18\,4\,{-2}\,{-1} ⁦8421⁩، ⁦2421⁩، 8 4 −2 −18\,4\,{-2}\,{-1}0101, 1011, 10110101، 1011، 1011
Non-weighted: no position weightsبێکێش: شوێنەکان کێشیان نییەExcess-3, Gray code⁦Excess-3⁩، کۆدی گرەی1000, 01111000، 0111
Alphanumeric: letters and symbols tooپیت و ژمارە: پیت و هێماکانیشASCII, EBCDIC, BaudotASCII، EBCDIC، Baudot0110101 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 2+2+1=52 + 2 + 1 = 5; in 8 4 −2 −18\,4\,{-2}\,{-1}, 1011 is 8−2−1=58 - 2 - 1 = 5. A non-weighted code has no position weights, so you read it from its table.

لە کۆدێکی کێشداردا کێشی 1 کۆ دەکەیتەوە: لە ⁦2421⁩ـدا 1011 دەکاتە 2+2+1=52 + 2 + 1 = 5؛ لە 8 4 −2 −18\,4\,{-2}\,{-1}ـدا 1011 دەکاتە 8−2−1=58 - 2 - 1 = 5. کۆدێکی بێکێش کێشی شوێنەکانی نییە، بۆیە لە خشتەکەیەوە دەیخوێنیتەوە.

Quick checkپشکنینی خێراWhich of these codes is weighted?کام لەم کۆدانە کێشدارە؟

Other decimal codesکۆدە دەییەکانی تر

Excess-3: BCD plus three⁦Excess-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ن.

The Excess-3 codeکۆدی ⁦Excess-3⁩
Decimal digit 8421 BCD ⁦8421⁩Excess-3کۆدی ⁦Excess-3⁩
000000011
100010100
200100101
300110110
401000111
501011000
601101001
701111010
810001011
910011100
Quick checkپشکنینی خێراWhat is the digit 6 in Excess-3? 6 بە ⁦Excess-3⁩ چییە؟

Other decimal codesکۆدە دەییەکانی تر

BCD ⇄ Excess-3, digit by digitکۆدی دەیی دووانی ⇄ ⁦Excess-3⁩، تاکژمارە بە تاکژمارە

  • BCD → Excess-3: add 0011 to every 4-bit group. 29 = 0010 1001 in BCD → 0101 1100 in Excess-3.
  • Excess-3 → BCD: subtract 0011 from 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⁩.
Quick checkپشکنینی خێراWhat is 45 in Excess-3?⁦45⁩ بە ⁦Excess-3⁩ چییە؟

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 9−7=29 - 7 = 2. 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 و 9−7=29 - 7 = 2. ئەمە تەواوکەری نۆیە، ڕێگای بۆ لێدەرکردن بە کۆکردنەوە (تەواوکەری نۆ و دە). کۆدێکی وا پێی دەڵێن خۆتەواوکەر. ⁦8421⁩ وا نییە: پێچەوانەکردنەوەی 7 (0111) 1000 دەدات کە 8ـە.

A whole number works the same way: invert every bit of 274 in Excess-3 and you get 725, and 999−274=725999 - 274 = 725.ژمارەی تەواویش هەمان شتە: هەموو ⁦274⁩ بە ⁦Excess-3⁩ پێچەوانە بکەرەوە، ⁦725⁩ وەردەگریت و 999−274=725999 - 274 = 725.
NumberژمارەExcess-3کۆدی ⁦Excess-3⁩
2740101 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 8 4 −2 −18\,4\,{-2}\,{-1} are self-complementing too.

جۆرج ستیبیتز ⁦Excess-3⁩ـی لەو ئامێرە کۆکەرەوە ڕیلەییەدا بەکار هێنا کە لە ⁦1937⁩ دروستی کرد. دواتر لە هەندێک سەرەتایی، مەکینەی پارەی دوکان و گیرفانی ساڵانی حەفتاکاندا بەکار هات. کۆدە کێشدارەکانی ⁦2421⁩ و 8 4 −2 −18\,4\,{-2}\,{-1}یش خۆتەواوکەرن.

Quick checkپشکنینی خێراIn Excess-3 the digit 3 is 0110. Invert its bits: 1001. Which digit is that?بە ⁦Excess-3⁩ 3 0110ـە. پێچەوانە بکەرەوە: 1001. ئەمە کام ؟

Exercisesڕاهێنانەکان

ExerciseڕاهێنانBCD additions without correctionکۆکردنەوەی کۆدی دەیی دووانی بەبێ ڕاستکردنەوە

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کۆکردنەوەی DecimalWorkingهەژمارAnswerوەڵام
(a)(أ)0011 + 01003+43 + 4no correctionبێ ڕاستکردنەوە0111 = 7
(b)(ب)0010 0011 + 0001 010123+1523 + 15no correctionبێ ڕاستکردنەوە0011 1000 = 38
(c)(ج)1000 0110 + 0001 001186+1386 + 13no correctionبێ ڕاستکردنەوە1001 1001 = 99
(d)(د)0100 0101 0000 + 0100 0001 0111450+417450 + 417no correctionبێ ڕاستکردنەوە1000 0110 0111 = 867

Every group sum is 9 or less with no carry, so no group needs +6+6.

کۆی هەموو کۆمەڵەیەک 9 یان کەمترە و نییە، بۆیە هیچ کۆمەڵەیەک پێویستی بە +6+6 نییە.

ExerciseڕاهێنانBCD additions with correctionکۆکردنەوەی کۆدی دەیی دووانی بە ڕاستکردنەوە

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کۆکردنەوەی DecimalWorkingهەژمارAnswerوەڵام
(a)(أ)1001 + 01009+49 + 41101 > 9 → +0110 = 1 00111101 > 9 ← +0110 = 1 00110001 0011 = 13
(b)(ب)1001 + 10019+99 + 91 0010: carry → +0110 → 10001 0010: ← +0110 ← 10000001 1000 = 18
(c)(ج)0110 0111 + 0101 001167+5367 + 53units 1010 > 9 → 0000, carry; tens 6+5+16 + 5 + 1 = 1100 > 9 → 0010, carryیەکان 1010 > 9 ← 0000، ؛ دەیان 6+5+16 + 5 + 1 = 1100 > 9 ← 0010، 0001 0010 0000 = 120
(d)(د)0001 0110 + 0001 010116+1516 + 15units 1011 > 9 → 0001, carry; tens 1+1+11 + 1 + 1 = 0011یەکان 1011 > 9 ← 0001، ؛ دەیان 1+1+11 + 1 + 1 = 00110011 0001 = 31
ExerciseڕاهێنانConvert and addبیگۆڕە و کۆی بکەرەوە

Convert to BCD and add: (a) 47+3847 + 38 (b) 28+1528 + 15.

بیانگۆڕە بۆ و کۆیان بکەرەوە: (أ) 47+3847 + 38 (ب) 28+1528 + 15.

Show answerوەڵامەکە پیشان بدە
  • (a) 0100 0111 + 0011 1000: units 0111 + 1000 = 1111 = 15>915 > 9 → + 0110 = 1 0101: digit 5, carry 1; tens 4+3+14 + 3 + 1 = 1000. Answer 1000 0101 = 85.
  • (b) 0010 1000 + 0001 0101: units 1000 + 0101 = 1101 = 13>913 > 9 → + 0110 = 1 0011: digit 3, carry 1; tens 2+1+12 + 1 + 1 = 0100. Answer 0100 0011 = 43.
  • (أ) 0100 0111 + 0011 1000: یەکان 0111 + 1000 = 1111 = 15>915 > 9 ← + 0110 = 1 0101: 5، 1؛ دەیان 4+3+14 + 3 + 1 = 1000. وەڵام 1000 0101 = ⁦85⁩.
  • (ب) 0010 1000 + 0001 0101: یەکان 1000 + 0101 = 1101 = 13>913 > 9 ← + 0110 = 1 0011: 3، 1؛ دەیان 2+1+12 + 1 + 1 = 0100. وەڵام 0100 0011 = ⁦43⁩.
ExerciseڕاهێنانOne pattern, three readingsیەک پێکهاتە، سێ خوێندنەوە

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: 1024+128+4+21024 + 128 + 4 + 2 = 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⁩.
  • (ج) : 1024+128+4+21024 + 128 + 4 + 2 = ⁦1158⁩. بە تەنها ژمارەکە ناڵێن؛ دەبێت کۆدەکە بزانیت.
Quick checkپشکنینی خێرا0111 + 0101 (7+57 + 5) gives 1100. What is the BCD answer?0111 + 0101 (7+57 + 5) 1100 دەدات. وەڵامی چییە؟

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).
Quick checkپشکنینی خێراWhy might banking software prefer decimal digits to binary fractions?بۆچی دەشێت بانک لە کەرتی پێ باشتر بێت؟

What is Binary Coded Decimal (BCD) and How is it Used in Automation?RealPars · Englishئینگلیزی · 96K viewsبینین · 2.8K likesلایک · Partبەشی 7:19–10:11 (ofلە 10:11)

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 (9+99 + 9 → 0010).تەنها ڕاستکردنەوەی کۆی سەروو 9 و لەبیرکردنی حاڵەتی (9+99 + 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. 99+199 + 1: 1001 1001 + 0000 0001 = 1001 1010; correcting only the units gives 1010 0000, still invalid.بڕیاردانی هەموو ڕاستکردنەوەکان تەنها لە کۆی یەکەمەوە. 99+199 + 1: 1001 1001 + 0000 0001 = 1001 1010؛ ڕاستکردنەوەی تەنها یەکان 1010 0000 دەدات کە هێشتا نادروستە.Work right to left and check each group after its incoming carry: 99+199 + 1 = 0001 0000 0000 = 100.لە ڕاستەوە بۆ چەپ کار بکە و هەر کۆمەڵەیەک دوای ئەوەی پێی گەیشت بپشکنە: 99+199 + 1 = 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: 9+99 + 9 = 0001 1000, not 1000.لە ئەو نوێیە: 9+99 + 9 = 0001 1000، نەک 1000.

Summaryپوختە

  • BCD writes each decimal digit as its own 4-bit group with weights 8, 4, 2, 1.
  • 1010 to 1111 are invalid; only 10 of the 16 patterns are used.
  • BCD is not binary: 37 = 0011 0111 in BCD but 100101 in 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 ( بە ). خۆتەواوکەرە: پێچەوانەکردنەوەی تەواوکەری نۆ دەدات.
Review questionsپرسیارەکانی پێداچوونەوە
Why is 9+99 + 9 the tricky case?بۆچی 9+99 + 9 حاڵەتە فێڵاوییەکەیە؟

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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

Binary Coded Decimal (BCD) & Douglas Adams' 42 - ComputerphileComputerphile · Englishئینگلیزی · 131K viewsبینین · 4.1K likesلایک · Partبەشی 0:20–14:07 (ofلە 14:07)

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زاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

The Gray Codeکۆدی گرەی

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.