Chapterبەش 3 · Lectureوانە 3.4
Signed Numbers: Sign-Magnitude, 1's and 2's Complementژمارە نیشانەدارەکان: نیشانە و نرخی ڕووت، تەواوکەری یەک و تەواوکەری دوو
How a computer stores negative integers with only 0s and 1s: unsigned numbers, the sign bit, and the three signed forms — sign-magnitude, 1's complement and 2's complement — with their ranges, their zeros, and why 2's complement is used everywhere today.
چۆن تەنها بە 0 و 1 هەڵدەگرێت: ، و سێ شێوەی نیشانەدار — ، و — لەگەڵ سنووری بەهاکانیان، سفرەکانیان و ئەوەی بۆچی ئەمڕۆ لە هەموو شوێنێک بەکار دێت.
What you will learnچی فێر دەبیت
- Give the range of unsigned numbers with n bits.
- Write a negative number in sign-magnitude, 1's complement and 2's complement.
- Read the decimal value of a signed number in each form (the weight trick).
- State the correct range of each form and explain why 2's complement has one zero and one extra negative value.
- بچووکترین و گەورەترین بە n بنووسیت.
- بە ، و بنووسیت.
- بە هەر شێوەیەک بێت بخوێنیتەوە و بەهاکەی بە بنووسیت (ڕێگای بۆ ).
- سنووری دروستی بەهاکانی هەر شێوەیەک بڵێیت و ڕوون بکەیتەوە بۆچی یەک سفر و یەک بەهای سالبی زیاتری هەیە.
Numbers with a signژمارە بە نیشانەوە
Everything in a computer's is bits. Some bits are instructions (orders for the ) and the rest are data. Data comes in a few formats:
هەموو شتێک لە . هەندێک لە (فەرمان بۆ ) و ئەوانی تر . چەند شێوەیەکی هەیە:
- Numbers: whole numbers () such as 25 or , and real numbers with a fraction part such as 3.75.
- Character codes: letters, digits and symbols, for example ASCII (a later lesson).
- ژمارە: وەک 25 یان و کە بەشی کەرتیان هەیە وەک 3.75.
- کۆدی نووسە: پیت، و هێما، بۆ نموونە (لە وانەیەکی دواتردا).
This lesson is about integers that can be negative. Bits are only 0 and 1. There is no minus sign inside a computer. So how can a computer store ? Engineers found three answers. You will learn all three, and why one of them won.
ئەم وانەیە دەربارەی کە دەتوانن سالب بن. تەنها 0 و 1ن و نیشانەی کەم (−) لە ناو نییە. کەواتە چۆن هەڵدەگرێت؟ ئەندازیاران سێ وەڵامیان دۆزییەوە. لێرەدا فێری هەر سێکیان دەبیت و دەزانیت بۆچی یەکێکیان سەرکەوت.
Unsigned numbers: only zero and upژمارە بێنیشانەکان: تەنها سفر و سەرەوە
The usual way to store a whole number is plain binary. With n bits there are different patterns of 0s and 1s. If every pattern means a number from 0 upwards, we call these numbers unsigned.
ڕێگای ئاسایی بۆ هەڵگرتنی سادەیە. بە n پێکهاتەی جیاوازی 0 و 1 هەیە. ئەگەر هەر پێکهاتەیەک ژمارەیەک بێت لە 0 بەرەو سەرەوە، پێیان دەڵێین .
A binary number with no sign bit: all its bits show the size, so it is never negative. With n bits it can hold 0 to .
ژمارەیەکی بەبێ : هەموو قەبارەکەی پیشان دەدەن، بۆیە هەرگیز سالب نییە. بە n بیت دەتوانێت 0 تا هەڵبگرێت.
An unsigned number with n bits lies between 0 and . With 8 bits: patterns, from 00000000 = 0 to 11111111 = 255.
وەک بە n لە نێوان 0 و ـدایە. بە 8 : پێکهاتە، لە 00000000 = 0 تا 11111111 = 255.
Why is 255 the largest? Add 1 to 11111111: every column becomes , so it writes 0 and carries 1. The last carry needs a ninth bit, and 1 00000000 is . Eight bits cannot hold it, so they stop at . A register that loses this ninth bit has an unsigned overflow (When the answer does not fit).
بۆچی 255 گەورەترینە؟ 1 بخە سەر 11111111: هەموو ستوونێک دەبێتە ، بۆیە 0 دەنووسێت و 1 دەگوازێتەوە. دوایین پێویستی بە نۆیەم هەیە و 1 00000000 دەکاتە . هەشت ناتوانن هەڵیبگرن، بۆیە لە دا دەوەستن. ئەو کە ئەم نۆیەمە لەدەست دەدات تووشی دەبێت (کاتێک وەڵامەکە جێی نابێتەوە).
This works only for positive numbers and zero. To store negative numbers we must give up something: one bit must tell the sign.
ئەمە تەنها بۆ و سفر کار دەکات. بۆ هەڵگرتنی دەبێت دەست لە شتێک هەڵبگرین: دەبێت نیشانەکە بڵێت.
The sign bitبیتی نیشانە
All three ways of storing signed numbers use the same idea: the leftmost bit (the ) is the sign bit.
هەر سێ ڕێگاکەی هەڵگرتنی هەمان بیرۆکە بەکار دەهێنن: لای چەپترین () .
- Sign bit 0 → the number is positive (or zero).
- Sign bit 1 → the number is negative.
- 0 ← ژمارەکە موجەبە (یان سفرە).
- 1 ← ژمارەکە سالبە.
The leftmost bit of a signed binary number: 0 means positive and 1 means negative.
لای چەپترین : 0 واتە موجەب و 1 واتە سالب.
A shopkeeper in the bazaar keeps a debt book. Each line has a small first column with a mark — owes or paid in advance — and then the amount. The amount is always written the same way; only the mark changes. The sign bit is that first column.
دوکاندارێک لە بازاڕ دەفتەرێکی قەرزی هەیە. هەر دێڕێک ستوونێکی بچووکی یەکەمی هەیە بە نیشانەیەک — قەرزدارە یان پێشەکی داوە — و پاشان بڕی پارەکە. بڕەکە هەمیشە بە هەمان شێوە دەنووسرێت؛ تەنها نیشانەکە دەگۆڕێت. ئەو ستوونە یەکەمەیە.
Where the analogy stops workingسنووری ئەم نموونەیە
The book can use as many digits as it needs, but a computer has a fixed number of bits. Because one bit is used for the sign, fewer bits are left for the size, so the largest number gets smaller.
دەفتەرەکە دەتوانێت هەر چەند پێویست بێت بەکاری بهێنێت، بەڵام ژمارەیەکی دیاریکراو هەیە. لەبەر ئەوەی یەک بۆ نیشانە دەڕوات، کەمتر بۆ قەبارەکە دەمێنێتەوە و گەورەترین ژمارە بچووکتر دەبێت.
The sign bitبیتی نیشانە
Three ways, one differenceسێ ڕێگا، یەک جیاوازی
The three ways are sign-magnitude, 1's complement and 2's complement. They agree on positive numbers: a positive number is always the sign bit 0 followed by its normal binary value. For example, in 5 bits is 01010 in all three. They differ only in how they write negative numbers.
سێ ڕێگاکە ئەمانەن: ، و . لەسەر یەک دەگرنەوە: هەمیشە 0ـە و لە دوایدا بەها ئاساییەکەی دێت. بۆ نموونە بە 5 لە هەر سێکیاندا 01010ـە. جیاوازییان تەنها لە نووسینی ژمارە سالبەکاندایە.
Way 1: sign-magnitudeڕێگای 1: نیشانە و نرخی ڕووت
Sign-magnitude is the way we write numbers on paper: a sign, then the size. In an n-bit number the sign bit is on the left and the magnitude (the size without the sign) fills the other bits. A negative number has the same magnitude bits as its positive partner; only the sign bit changes from 0 to 1.
هەمان ئەو ڕێگایەیە کە لەسەر کاغەز ژمارەی پێ دەنووسین: نیشانەیەک و پاشان قەبارەکە. لە ژمارەیەکی n بیتیدا لای چەپە و (قەبارەکە بەبێ نیشانە) تر پڕ دەکاتەوە. هەمان هاوتا موجەبەکەی هەیە؛ تەنها لە 0ـەوە دەبێتە 1.
A way to write signed binary numbers: the leftmost bit is the sign and the other bits are the magnitude (the size without the sign). It has two zeros, and .
ڕێگەیەکە بۆ نووسینی : لای چەپترین بیت و بیتەکانی تر نرخی ڕووتی ژمارەکەن (قەبارەکەی بەبێ نیشانە). دوو سفری هەیە: و .
| Numberژمارە | Bits | Sign bit | Magnitude |
|---|---|---|---|
| (8 bits) (8 ) | 00010010 | 0 | 0010010 = 18 |
| (8 bits) (8 ) | 10010010 | 1 | 0010010 = 18 |
| (6 bits) (6 ) | 000111 | 0 | 00111 = 7 |
| (6 bits) (6 ) | 100111 | 1 | 00111 = 7 |
| (8 bits) (8 ) | 01111111 | 0 | 1111111 = 127 |
| (8 bits) (8 ) | 11111111 | 1 | 1111111 = 127 |
Way 1: sign-magnitudeڕێگای 1: نیشانە و نرخی ڕووت
Reading a sign-magnitude numberخوێندنەوەی ژمارەیەک بە نیشانە و نرخی ڕووت
To find the decimal value, split the bits into two parts: the sign bit, and the magnitude bits. Change the magnitude to decimal, then put the sign in front.
بۆ دۆزینەوەی بەها ، بکە بە دوو بەش: و . بگۆڕە بۆ و پاشان نیشانەکە بخە پێشی.
1 00101011 0010101Sign bit 1 → negative. Magnitude
0010101= . Value: .1ـە ← سالب.
0010101= . بەها: .0 11101110 1110111Sign bit 0 → positive. Magnitude
1110111= . Value: .0ـە ← موجەب.
1110111= . بەها: .
Way 1: sign-magnitudeڕێگای 1: نیشانە و نرخی ڕووت
Range and the two zerosسنووری بەهاکان و دوو سفرەکە
With n bits, the magnitude has bits, so its largest value is . Each magnitude can be positive or negative:
بە n ، هەیە، بۆیە گەورەترین بەهای ـە. هەر دەتوانێت موجەب یان سالب بێت:
For 8 bits: (11111111) up to (01111111).
بۆ 8 : (11111111) تا (01111111).
Count the values: 127 negative + 127 positive + zero = 255. But 8 bits have 256 patterns. Where is the missing one? Zero is written twice: 00000000 () and 10000000 (). Two zeros waste a pattern, and a circuit must check both when it asks "is this zero?". Adding is also harder: the circuit must look at the signs first, then decide to add or subtract the magnitudes.
بەهاکان بژمێرە: 127 سالب + 127 موجەب + سفر = 255. بەڵام 8 256 پێکهاتەیان هەیە. ئەوەی ون بووە لە کوێیە؟ سفر دوو جار نووسراوە: 00000000 () و 10000000 (). دوو سفر پێکهاتەیەک بە فیڕۆ دەدەن و کاتێک دەپرسێت «ئایا ئەمە سفرە؟» دەبێت هەردووکیان بپشکنێت. کۆکردنەوەش قورسترە: سەرەتا دەبێت سەیری نیشانەکان بکات و پاشان بڕیار بدات کۆ بکاتەوە یان لێک دەربکات.
Way 2: 1's complementڕێگای 2: تەواوکەری یەک
In 1's complement, positive numbers are the same as before. To make a negative number, take the positive number with all its bits (sign bit included) and invert every bit: each 0 becomes 1 and each 1 becomes 0. You met this operation in 1's and 2's complements.
لە وەک پێشوون. بۆ دروستکردنی ، بە هەموو وەربگرە () و هەموو پێچەوانە بکەرەوە: هەر 0ـێک دەبێتە 1 و هەر 1ـێک دەبێتە 0. ئەم کارەت لە تەواوکەری یەک و تەواوکەری دوو بینی.
| Number (5 bits)ژمارە (5 ) | Positive formشێوەی موجەب | Invert every bitهەموو پێچەوانە بکەرەوە | 1's complement |
|---|---|---|---|
00011 | → | 11100 | |
01010 | → | 10101 |
The handout reaches the same answer from the sign-magnitude form: = 1 0011; keep the sign bit 1 and invert only the four magnitude bits → 1 1100. Both routes give the same bits.
پەڕەی دەستەکە لە شێوەی دەگاتە هەمان وەڵام: = 1 0011؛ بە 1 بهێڵەوە و تەنها چوار پێچەوانە بکەرەوە ← 1 1100. هەردوو ڕێگاکە هەمان دەدەن.
To read a 1's complement number that starts with 1, invert it back: 10101 → 01010 = 10, so 10101 is .
بۆ خوێندنەوەی ژمارەیەکی کە بە 1 دەست پێدەکات، دیسان پێچەوانەی بکەرەوە: 10101 ← 01010 = 10، کەواتە 10101 بەهاکەی ـە.
Way 2: 1's complementڕێگای 2: تەواوکەری یەک
Range of 1's complementسنووری بەهاکانی تەواوکەری یەک
1's complement has exactly the same range as sign-magnitude, and it also has two zeros: 0…0 () and 1…1 (, the inverse of ).
ڕێک هەمان سنووری بەهاکانی هەیە و ئەویش دوو سفری هەیە: 0…0 () و 1…1 (، پێچەوانەی ).
For 4 bits: largest = 0111; smallest = 1000 (invert 0111).
بۆ 4 : گەورەترین = 0111؛ بچووکترین = 1000 (پێچەوانەی 0111).
Way 3: 2's complementڕێگای 3: تەواوکەری دوو
In 2's complement, positive numbers are again the same. To make a negative number: write the positive number, invert every bit (1's complement), then add 1.
لە دیسان وەک خۆیانن. بۆ دروستکردنی : بنووسە، هەموو پێچەوانە بکەرەوە ()، پاشان 1 زیاد بکە.
- Write the positive numberژمارە موجەبەکە بنووسە
in 5 bits is
01010.بە 5 دەکاتە
01010. - Invertپێچەوانە بکەرەوە
Invert every bit:
10101(this is in 1's complement).هەموو پێچەوانە بکەرەوە:
10101(ئەمە ـە بە ). - Add 11 زیاد بکە
Add 1:
10101+ 1 =10110. So is10110in 5-bit 2's complement.1 زیاد بکە:
10101+ 1 =10110. کەواتە بە 5 بیتی10110ـە.
The handout starts from the sign-magnitude form 1 1010 and inverts only the magnitude bits → 1 0101, then adds 1 → 1 0110. The result is the same.
پەڕەی دەستەکە لە شێوەی 1 1010ـەوە دەست پێدەکات و تەنها پێچەوانە دەکاتەوە ← 1 0101، پاشان 1 زیاد دەکات ← 1 0110. ئەنجامەکە هەمانە.
Way 3: 2's complementڕێگای 3: تەواوکەری دوو
Why does “invert and add 1” work?بۆچی «پێچەوانەکردنەوە و زیادکردنی 1» کار دەکات؟
In 2's complement, is all ones (11111 in 5 bits), because must give 0. Now look at . Taking away from all ones never needs a borrow: each and each . So is just with every bit inverted. Add 1 and you have .
لە هەمووی 1ـە (11111 بە 5 )، چونکە دەبێت سفر بدات. ئێستا سەیری بکە. لێدەرکردنی لە ژمارەیەک کە هەمووی 1ـە هەرگیز ناوێت: هەر و هەر . کەواتە هەمان ـیە بە هەموو پێچەوانەکراوە. 1ـی بۆ زیاد بکە و ـت دەست دەکەوێت.
Imagine a taxi's distance meter showing 00000 and the car is pushed back 1 km. The digits roll back to 99999. So "one less than zero" looks like all nines. In binary the same thing happens with all ones: one less than 0000 is 1111, which 2's complement reads as .
وای دابنێ عەدادی تەکسییەک 00000 پیشان دەدات و ئۆتۆمبێلەکە 1 کیلۆمەتر بۆ دواوە دەبرێت. ژمارەکان دەگەڕێنەوە بۆ 99999. کەواتە «یەک کەمتر لە سفر» وەک هەمووی نۆ دەردەکەوێت. لە هەمان شت بە هەمووی 1 ڕوو دەدات: یەک کەمتر لە 0000 دەکاتە 1111 کە بە دەیخوێنێتەوە.
Where the analogy stops workingسنووری ئەم نموونەیە
A real meter has ten digits per place and is not meant to go backwards. The idea that carries over is only this: when you count down past zero, you land on the largest pattern.
عەدادی ڕاستەقینە بۆ هەر خانەیەک دە هەیە و بۆ ئەوە دروست نەکراوە بەرەو دواوە بڕوات. ئەوەی لێرەدا دەمێنێتەوە تەنها ئەمەیە: کاتێک بە دابەزین لە سفر تێدەپەڕیت، دەگەیتە گەورەترین پێکهاتە.
Way 3: 2's complementڕێگای 3: تەواوکەری دوو
The 2's complement wheelبازنەی تەواوکەری دوو
Put all 16 patterns of 4 bits on a wheel, in counting order. Adding 1 moves one step clockwise. Watch what happens after .
هەموو 16 پێکهاتەی 4 بە ڕیزی ژماردن لەسەر بازنەیەک دابنێ. زیادکردنی 1 یەک هەنگاو بە ئاراستەی میلی کاتژمێر دەتبات. سەیر بکە دوای چی ڕوو دەدات.


The right half of the wheel (sign bit 0) holds 0 to . The left half (sign bit 1) holds to . There is only one zero, so all 16 patterns are used, and the negative side gets one extra value:
نیوەی ڕاستی بازنەکە ( 0) 0 تا هەڵدەگرێت. نیوەی چەپ ( 1) تا . تەنها یەک سفر هەیە، بۆیە هەموو 16 پێکهاتەکە بەکار دێن و لای سالب یەک بەهای زیاتری بەر دەکەوێت:
4 bits: to . 8 bits: to . 16 bits: to .
4 : تا . 8 : تا . 16 : تا .
Way 3: 2's complementڕێگای 3: تەواوکەری دوو
Reading a 2's complement number quicklyخوێندنەوەی خێرای ژمارەیەکی تەواوکەری دوو
There is a quick way to read any 2's complement number: give the sign bit a negative weight, , and add the normal weights of the other 1 bits. In 8 bits the sign bit weighs .
ڕێگایەکی خێرا هەیە بۆ خوێندنەوەی هەر ژمارەیەکی : سالب بدە بە ، واتە . پاشان ئاسایی تر کە 1ن بخە سەری. لە 8 دەژمێردرێت.
11011001 = : the sign bit has the weight .11011001 = : بە دەژمێردرێت.CêITThis also explains the wheel: 1000 in 4 bits is just the sign bit, ; 1111 is .
ئەمە بازنەکەش ڕوون دەکاتەوە: 1000 بە 4 تەنها ، واتە ؛ 1111 دەکاتە .
Two's complement with a −128 sign weight, and the quick ways to make a negative number: invert and add 1.
کە تێیدا بەهای −128ـی هەیە، لەگەڵ ڕێگا خێراکانی دروستکردنی : پێچەوانەکردنەوە و زیادکردنی 1.
Chapters 3:07-8:59: the sign bit weighs −128; checked a frame (−128 + 64 + 32 + 16 + 8).
بەشەکانی 3:07 تا 8:59: بەهای −128ـی هەیە؛ لە ڤیدیۆکەدا: .
One number, three ways: یەک ژمارە بە سێ ڕێگا:
The lecture asks for as an 8-bit number in all three forms. Here are all three, including the sign-magnitude form that the slide skips.
وانەکە داوای دەکات وەک ژمارەیەکی 8 بیتی بە هەر سێ شێوەکە. ئەوە هەر سێکیانە، لەگەڵ شێوەی کە سلایدەکە بازی بەسەردا دەدات.
- Write in 8 bits بە 8 بیت بنووسە
, so =
00100111.، کەواتە =
00100111. - Sign-magnitudeنیشانە و نرخی ڕووت
Change only the sign bit:
10100111.تەنها بگۆڕە:
10100111. - 1's complementتەواوکەری یەک
Invert every bit of
00100111:11011000.هەموو
00100111پێچەوانە بکەرەوە:11011000. - 2's complementتەواوکەری دوو
Add 1 to the 1's complement:
11011000+ 1 =11011001.1 بخە سەر :
11011000+ 1 =11011001. - Check with the weightبە ـی بیتی نیشانە بیپشکنە
. ✓
. ✓
All the ways side by sideهەموو ڕێگاکان لە تەنیشت یەکەوە
Here is every 4-bit pattern read in five ways. In the first four columns the top half (sign bit 0) is the same everywhere, and the bottom half shows the differences. The last column, excess-8, is one more signed code; the next screen explains it.
ئەمە هەموو پێکهاتەیەکی 4 بیتییە کە بە پێنج ڕێگا خوێندراوەتەوە. لە چوار ستوونی یەکەمدا نیوەی سەرەوە ( 0) لە هەموو شوێنێک وەک یەکە و نیوەی خوارەوە جیاوازییەکان پیشان دەدات. ستوونی کۆتایی، excess-8، کۆدێکی نیشانەداری ترە کە شاشەی داهاتوو ڕوونی دەکاتەوە.
bits | Unsigned | Sign-magnitude | 1's complement | 2's complement | Excess-8کۆدی excess-8 |
|---|---|---|---|---|---|
0000 | 0 | 0 | 0 | 0 | |
0001 | 1 | ||||
0010 | 2 | ||||
0011 | 3 | ||||
0100 | 4 | ||||
0101 | 5 | ||||
0110 | 6 | ||||
0111 | 7 | ||||
1000 | 8 | 0 | |||
1001 | 9 | ||||
1010 | 10 | ||||
1011 | 11 | ||||
1100 | 12 | ||||
1101 | 13 | ||||
1110 | 14 | ||||
1111 | 15 |
| Formشێوە | Range with n bitsسنوورەکان بە n | 8 bitsبە 8 | Zerosسفرەکان |
|---|---|---|---|
| Unsigned | … | 0 … 255 | 1 |
| Sign-magnitude | … | … | 2 |
| 1's complement | … | … | 2 |
| 2's complement | … | … | 1 |
| Excess-K ()کۆدی excess-K () | … | … | 1 |
All the ways side by sideهەموو ڕێگاکان لە تەنیشت یەکەوە
A fourth code: excess-Kکۆدێکی چوارەم: excess-K
Excess-K (also called a biased or offset code) has no sign bit at all. To store a number, add a fixed number K, the bias, and write the result as an ordinary unsigned number. With 4 bits and (excess-8): → 0000, → 1000 and → 1111. To read a pattern, take its unsigned value and subtract K: 0101 is .
Excess-K (کۆدی biased یان offsetیش پێی دەڵێن) هیچ نییە. بۆ هەڵگرتنی ژمارەیەک، ژمارەیەکی جێگیر (K) دەخەینە سەری و ئەنجامەکە وەک ئاسایی دەنووسین. بە 4 و (excess-8): ← 0000، ← 1000 و ← 1111. بۆ خوێندنەوەی پێکهاتەیەک، بەها بێنیشانەکەی وەربگرە و K لێ دەربکە: 0101 دەکاتە .
- Numeric order:
0000is the smallest number and1111the largest, so a circuit can compare two numbers exactly like unsigned numbers. - One zero (
1000), like 2's complement. In fact excess-8 is 2's complement with the leftmost bit flipped: compare the last two columns. - Where it is used: the exponent of floating-point numbers. The IEEE 754 single-precision format stores the exponent with , so an exponent of 0 is
01111111.
- ڕیزی ژمارەکان:
0000بچووکترین ژمارەیە و1111گەورەترین، بۆیە دەتوانێت دوو ژمارە ڕێک وەک بەراورد بکات. - یەک سفر (
1000)، وەک . لە ڕاستیدا excess-8 هەمان بەڵام لای چەپترین پێچەوانە کراوەتەوە: دوو ستوونی کۆتایی بەراورد بکە. - لە کوێ بەکار دێت: ژمارە floating-pointـەکان. شێوازی single precisionـی IEEE 754 بە هەڵدەگرێت، بۆیە 0 دەبێتە
01111111.
Exercisesڕاهێنانەکان
Find the decimal value of these 8-bit sign-magnitude numbers: (a) 10010101 (b) 01110111 (c) 00010111.
ئەم ژمارە 8 بیتییانە بە نووسراون. بەهاکەیان بە بدۆزەرەوە: (أ) 10010101 (ب) 01110111 (ج) 00010111.
Hintئاماژە
Split off the sign bit first.
سەرەتا جیا بکەرەوە.
Show answerوەڵامەکە پیشان بدە
- (a) sign 1, magnitude
0010101= 21 → - (b) sign 0, magnitude
1110111= 119 → - (c) sign 0, magnitude
0010111= 23 →
- (أ) نیشانە 1،
0010101= 21 ← - (ب) نیشانە 0،
1110111= 119 ← - (ج) نیشانە 0،
0010111= 23 ←
Write each number as an 8-bit number in sign-magnitude, 1's complement and 2's complement: , , .
هەر ژمارەیەک وەک ژمارەیەکی 8 بیتی بنووسە بە ، و : ، ، .
Show answerوەڵامەکە پیشان بدە
| Numberژمارە | Positiveموجەب | Sign-magnitude | 1's complement | 2's complement |
|---|---|---|---|---|
00100111 | 10100111 | 11011000 | 11011001 | |
00010011 | 10010011 | 11101100 | 11101101 | |
00011001 | 10011001 | 11100110 | 11100111 |
Check : . Check : .
پشکنینی : . پشکنینی : .
Read the 8-bit pattern 10110110 as an unsigned number, in sign-magnitude, in 1's complement and in 2's complement.
پێکهاتەی 8 بیتیی 10110110 بخوێنەرەوە وەک ، بە ، بە و بە .
Show answerوەڵامەکە پیشان بدە
- Unsigned: = 182
- Sign-magnitude: sign 1, magnitude
0110110= 54 → - 1's complement: invert →
01001001= 73 → - 2's complement: =
- : = 182
- : نیشانە 1،
0110110= 54 ← - : پێچەوانە ←
01001001= 73 ← - : =
(a) Write in 6-bit sign-magnitude, 1's complement and 2's complement. (b) Give the range of each form for 6 bits.
(أ) بە ، و 6 بیتی بنووسە. (ب) سنووری بەهاکانی هەر شێوەیەک بۆ 6 بنووسە.
Show answerوەڵامەکە پیشان بدە
- (a) =
001101; sign-magnitude101101; 1's complement110010; 2's complement110011(). - (b) Sign-magnitude and 1's complement: to . 2's complement: to . (Unsigned: 0 to 63.)
- (أ) =
001101؛101101؛110010؛110011(). - (ب) و : تا . : تا . (: 0 تا 63.)
A lab experiment gives whole numbers from to . (a) Are 4 bits enough? (b) Which 4-bit codes of this lesson can hold every result? (c) Which one would you choose, and why? (d) Write and in your code.
ئەزموونێکی تاقیگە لە تا دەدات. (أ) ئایا 4 بەسە؟ (ب) کام کۆدی 4 بیتیی ئەم وانەیە دەتوانێت هەموو ئەنجامەکان هەڵبگرێت؟ (ج) کامیان هەڵدەبژێریت و بۆچی؟ (د) و بە کۆدەکەی خۆت بنووسە.
Hintئاماژە
Count the values first, then compare with each code's range.
سەرەتا بەهاکان بژمێرە، پاشان لەگەڵ سنووری هەر کۆدێک بەراوردیان بکە.
Show answerوەڵامەکە پیشان بدە
- (a) Yes: … is 12 values, and 4 bits give 16 patterns.
- (b) Sign-magnitude and 1's complement ( … ), 2's complement and excess-8 ( … ). Unsigned numbers cannot hold the negative results.
- (c) 2's complement: one zero, and the same adder works for every sum. Excess-8 is a good second choice when the results must be compared or sorted, because its patterns are in numeric order.
- (d) 2's complement: =
1011, =0110. Excess-8: →0011, →1110. (A custom excess-5 code would even map … to0000…1011.)
- (أ) بەڵێ: … دەکاتە 12 بەها و 4 16 پێکهاتە دەدەن.
- (ب) و ( … )، و excess-8 ( … ). ناتوانن ئەنجامە سالبەکان هەڵبگرن.
- (ج) : یەک سفری هەیە و هەمان بۆ هەموو کۆکردنەوەیەک کار دەکات. ئەگەر ئەنجامەکان دەبێت بەراورد یان ڕیز بکرێن، excess-8 هەڵبژاردنێکی باشی دووەمە، چونکە پێکهاتەکانی بە ڕیزی ژمارەکانن.
- (د) : =
1011، =0110. Excess-8: ←0011، ←1110. (کۆدێکی excess-5ـی تایبەت تەنانەت … دەگۆڕێت بۆ0000…1011.)
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Fixچارەسەر |
|---|---|
Inverting a number that is not yet n bits long: as 101 → 010.پێچەوانەکردنەوەی ژمارەیەک پێش ئەوەی n بێت: وەک 101 ← 010. | Pad to the full width first: 00000101 → 11111010 → 11111011.سەرەتا تا پانیی تەواو سفر زیاد بکە: 00000101 ← 11111010 ← 11111011. |
| Forgetting the , so the answer is the 1's complement.لەبیرکردنی ، بۆیە وەڵامەکە . | 2's complement = invert and add 1. Check with the weight. = پێچەوانەکردنەوە و زیادکردنی 1. بە ـی بیپشکنە. |
Reading 11011001 as (as if it were sign-magnitude).خوێندنەوەی 11011001 وەک (وەک ئەوەی بێت). | In 2's complement the sign bit weighs : .لە دەژمێردرێت: . |
| Using the sign-magnitude range for 2's complement ( … ).بەکارهێنانی سنووری بۆ ( … ). | 2's complement has one more negative value: … . یەک بەهای سالبی زیاترە: … . |
Thinking 1000 is in 2's complement.وا بزانیت 1000 لە ـە. | 2's complement has only one zero; 1000 is in 4 bits. تەنها یەک سفری هەیە؛ 1000 بە 4 ـە. |
| Changing a positive number when converting it.دەستکاریکردنی کاتێک بۆ شێوەیەکی نیشانەدار دەیگۆڕیت. | Positive numbers are the same in all three forms; only negatives change. لە هەر سێ شێوەکەدا وەک یەکن؛ تەنها سالبەکان دەگۆڕێن. |
Summaryپوختە
- n bits give patterns; unsigned numbers use them for 0 … .
- Signed numbers use the leftmost bit as the sign bit: 0 = positive, 1 = negative.
- Positive numbers are the same in all three forms.
- Sign-magnitude: change only the sign bit. Range , two zeros.
- 1's complement: invert every bit. Same range, two zeros.
- 2's complement: invert every bit, then add 1. Range … , one zero. The sign bit weighs .
- Excess-K: add a bias K and store the result unsigned. One zero, patterns in numeric order; used for floating-point exponents.
- Computers use 2's complement because one adder then handles every case.
- n پێکهاتە دەدەن؛ بۆ 0 … بەکاریان دەهێنن.
- لای چەپترین وەک بەکار دەهێنن: 0 = موجەب، 1 = سالب.
- لە هەر سێ شێوەکەدا وەک یەکن.
- : تەنها بگۆڕە. سنوورەکان ، دوو سفر.
- : هەموو پێچەوانە بکەرەوە. هەمان سنوور، دوو سفر.
- : هەموو پێچەوانە بکەرەوە، پاشان 1 زیاد بکە. سنوورەکان … ، یەک سفر. بە دەژمێردرێت.
- Excess-K: ژمارەیەکی جێگیر (K) زیاد بکە و ئەنجامەکە وەک هەڵبگرە. یەک سفری هەیە و پێکهاتەکانی بە ڕیزی ژمارەکانن؛ بۆ ژمارە floating-pointـەکان بەکار دێت.
- بەکار دەهێنن چونکە ئەو کاتە یەک هەموو حاڵەتەکان دەکات.
What is in 8-bit 2's complement? بە تەواوکەری دووی 8 بیتی چییە؟
11111111 (all ones): .
11111111 (هەمووی 1): .
Why does sign-magnitude have two zeros?بۆچی نیشانە و نرخی ڕووت دوو سفری هەیە؟
Because the magnitude 0 can carry either sign: 0000… is and 1000… is .
چونکە 0 دەتوانێت هەر دوو نیشانەکە هەڵبگرێت: 0000… ـە و 1000… ـە.
How many values can 8-bit 2's complement hold?تەواوکەری دووی 8 بیتی چەند بەها هەڵدەگرێت؟
256: from to , including one zero.
256: لە تا ، لەگەڵ یەک سفر.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Three ways to store negative numbers — sign bit, 1's complement, 2's complement — and why 2's complement wins.
سێ ڕێگای هەڵگرتنی (، و ) و بۆچی لە هەمووان باشترە.
Chapters: 0:26 sign bit, 2:58 problems with the sign bit, 4:20 one's complement, 9:39 two's complement.
بەشەکان: 0:26 ، 2:58 گرفتەکانی ، 4:20 ، 9:39 .
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Adding and Subtracting Signed Numbersکۆکردنەوە و لێدەرکردنی ژمارە نیشانەدارەکان
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 ن.