मुख्य सामग्री पर जाएँ

सिलेबस · CS कंप्यूटर विज्ञान और सूचना प्रौद्योगिकी

विषय के सभी टॉपिक
C प्रोग्रामिंग की बुनियाद6
ऐरे और पॉइंटर7
रिकर्शन6
लिंक्ड लिस्ट, स्टैक और क्यू3
ट्री, बाइनरी सर्च ट्री और हीप3
ग्राफ की बुनियाद3
एल्गोरिदम की बुनियाद3
असतत गणित की बुनियाद15
डिजिटल लॉजिक की बुनियाद22
कंप्यूटर संगठन की बुनियाद3
ऑपरेटिंग सिस्टम की बुनियाद5

Sign-magnitude और one's-complement arithmetic

पाठ 53 / 768 मिनटमुफ़्त

पहले representation का contract लिखें

केवल bits से signed मान तय नहीं होता। इस पाठ में n≥2 के तीन n-bit integer encodings की तुलना है; fractional bits नहीं हैं। Boolean variable पर prime अब भी NOT है; यहाँ “one's complement” integer representation का नाम भी है और negatives बनाने में प्रयुक्त bitwise inversion का भी।

पूर्वज्ञान: unsigned binary और two's complement। लक्ष्य: वैकल्पिक signed encodings पढ़ना, width बढ़ाकर मान सुरक्षित रखना और हर जगह two's-complement addition लगाने के बजाय सही arithmetic नियम चुनना। दो representations में zero के दो patterns हैं, इसलिए zero-result का output contract भी स्पष्ट करेंगे।

Sign-magnitude में top bit s sign है और शेष n−1 bits unsigned magnitude m हैं। मान (−1)^s m है। पाँच bits में 10110 का अर्थ −6 है, −10 नहीं। Negative zero 10000 और positive zero 00000 हैं। Bits अलग होने पर भी दोनों का numerical मान zero है। सीमा −(2^(n−1)−1) से +(2^(n−1)−1) है।

One's complement में nonnegative संख्या सामान्य zero-leading binary pattern है। Negative −m के लिए m के n-bit positive pattern के सभी bits उलटते हैं। Top-bit-one pattern का unsigned मान U हो तो signed मान U−(2^n−1) है। इसलिए पाँच-bit 11001 का U=25 और मान 25−31=−6 है। All-ones 11111 negative zero है। सीमा sign-magnitude जैसी है।

तुलना में पाँच-bit two's complement का −6, 11010 है; zero केवल 00000 है और सीमा −16…15 है। अतिरिक्त negative मान दूसरे zero-pattern को अलग संख्या के लिए उपयोग करने से मिलता है, अतिरिक्त storage bit से नहीं।

पाँच-bit representation−6Zero patternsन्यूनतम मान
Sign-magnitude1011000000, 10000−15
One's complement1100100000, 11111−15
Two's complement1101000000−16

Encoding, negation और widening

हल किया उदाहरण 1: −19 को आठ bits में encode करें। Positive pattern 00010011 है। Sign-magnitude में केवल sign बदलता है: 10010011। One's complement में सभी आठ bits उलटते हैं: 11101100। Two's complement में inverted pattern में 1 जोड़ते हैं: 11101101। हर एक को उसके अपने decoding नियम से जाँचें।

Sign-magnitude negation में केवल sign bit बदलता है। One's complement में सभी bits बदलते हैं। दोनों operations दो zeros को आपस में बदलते हैं। Two's complement के invert-and-add-one में पहले पढ़ी most-negative सीमा आती है। Symmetric alternate encodings में ऐसा nonzero negation overflow नहीं, क्योंकि हर representable nonzero magnitude के दोनों signs उपलब्ध हैं।

Sign-magnitude को widen करते समय sign नए top पर रखें और magnitude से पहले zeros जोड़ें। पाँच-bit 10110 (−6) आठ-bit 10000110 बनता है। केवल sign bit दोहराकर 11110110 बनाने से −118 मिलेगा। One's complement में sign bit दोहरता है: 11001 से 11111001। जाँच: 249−255=−6। One's तथा two's complement दोनों में sign extension काम करता है, पर उनके negative patterns समान नहीं हैं। Zero का sign सुरक्षित रखने को कहा हो तो उसी zero की विस्तृत encoding रखें; केवल numerical zero चाहिए तो positive zero में canonicalize कर सकते हैं।

Sign-magnitude addition में magnitudes इस्तेमाल करें

Signs समान हों तो magnitudes जोड़ें, वही sign रखें और जाँचें कि magnitude, 2^(n−1)−1 से बड़ा तो नहीं। Signs अलग हों तो बड़ी magnitude में से छोटी घटाएँ और बड़ी magnitude का sign लें। Magnitudes बराबर हों तो numerical उत्तर zero है; हमारे worked sign-magnitude algorithm में positive zero लौटता है।

हल किया उदाहरण 2: पाँच bits में −9+6 के magnitudes 9 और 6 हैं। अंतर 3 और sign negative है: 10011। Patterns को सीधे जोड़ने पर 11001+00110=11111 मिलता है, जिसका sign-magnitude अर्थ −15 है, −3 नहीं। इसी कारण इस representation को sign-aware control चाहिए।

−11+(−7) में magnitude 18 है, जो 15 से अधिक है; exact signed overflow होता है। Truncated magnitude को exact उत्तर न मानें। केवल numerical addition पूछा हो तो overflow बताएँ, मनमाना wraparound contract न बनाएँ।

One's-complement addition और end-around carry

दो n-bit patterns को unsigned bit strings की तरह जोड़ें। Bit n−1 के बाहर carry निकले तो उसे नीचे के n-bit result में वापस जोड़ें। यह end-around carry है, two's complement जैसा carry discard नहीं। Correction के बाद one's complement में decode करें और exact signed योग को अलग से range में जाँचें। हम पहले raw zero-pattern दिखाते हैं; positive zero में canonicalize तभी करते हैं जब कहा जाए।

Carry वापस क्यों आता है? ऊपरी carry का भार 2^n है और modulo 2^n−1 में 2^n, 1 के congruent है। Carry fold करने से आवश्यक residue सुरक्षित है। दोनों zero patterns zero residue दर्शाते हैं। बिना carry-in दो n-bit operands के लिए एक fold पर्याप्त है: अधिकतम योग 2^(n+1)−2 है, इसलिए low bits और single carry का योग 2^n−1 से अधिक नहीं होगा। यह encoding arithmetic का कारण है, signed सीमा अनदेखी करने की छूट नहीं।

हल किया उदाहरण 3: पाँच-bit 7+(−3) लें। Encoding 00111+11100=1 00011 है। Carry fold करें: 00011+1=00100, अर्थात +4। Carry छोड़ने पर +3 मिलता और गलत होता। −7+3 के लिए 11000+00011=11011 है, outer carry नहीं; 27−31=−4। 7+(−7) में 00111+11000=11111 मिलता है, जो raw negative-zero encoding है; numerical result zero है।

हल किया उदाहरण 4: 12+7 में 01100+00111=10011 मिलता है, जो −12 decode होता है। Exact 19, −15…15 से बाहर है, इसलिए outer carry न होने पर भी overflow है। End-around carry encoding arithmetic का हिस्सा है, signed overflow test नहीं। a−b में one's-complement b के सभी bits उलटकर यही addition करें; शुरुआत में अतिरिक्त 1 न जोड़ें। पाँच-bit 9−4 में 01001+11011=1 00100 और carry fold के बाद 00101=5 मिलता है।

मुख्य बातें और गलतियों की जाँच

  1. Sign bit पढ़ने से पहले width और encoding लिखें। Pattern 10000 तीनों representations में क्रमशः negative zero, −15 और −16 है।
  2. Sign-magnitude तथा one's complement में 2^n patterns, लेकिन 2^n−1 अलग numerical values हैं। उनके दो zeros की bitwise equality और numerical equality एक नहीं हैं।
  3. Sign-magnitude में sign/magnitude cases चाहिए। One's complement में end-around carry चाहिए। Two's complement में retained result के लिए outer carry छोड़ते हैं।
  4. Operands decode करें, exact गणित करें, range जाँचें और algorithm का result decode करें। इससे hardware steps से स्वतंत्र overflow जाँच मिलता है।
  5. Widening और negation representation-विशिष्ट हैं; केवल समानता देखकर नियम न बदलें। Zero normalization भी बताए गए output contract में ही करें।

मौलिक अभ्यास

ये छह single-correct MCQ सीखने के लिए बनाए गए मौलिक प्रश्न हैं, पिछले वर्षों के प्रश्न नहीं। हर प्रश्न में ठीक एक विकल्प चुनें।

C01. पाँच-bit 10000 को क्रमशः sign-magnitude, one's complement और two's complement में decode करें।

A. −16, −16, −16 B. Negative zero, −15, −16 C. Negative zero, −16, −15 D. −8, −15, −16

उत्तर: B

A गलत है: केवल two's complement यहाँ −16 देता है।

B सही है: sign-magnitude की magnitude zero; one's complement में 16−31=−15; two's complement में 16−32=−16।

C गलत है: complement representations की सीमाएँ उलटी हैं।

D गलत है: sign-magnitude के चारों low bits zero हैं।

C02. कौन-सा आठ-bit sign-magnitude pattern पाँच-bit 10110 का मान बचाता है?

A. 11110110 B. 00010110 C. 10000110 D. 10010110

उत्तर: C

A गलत है: magnitude positions में sign भरने से −118 मिलता है।

B गलत है: sign-magnitude में यह +22 है।

C सही है: sign 1 रखें और magnitude 6 सात bits में लिखें।

D गलत है: सात-bit magnitude 22 से −22 मिलता है।

C03. पाँच-bit one's-complement addition और end-around carry से 9+(−5) का pattern क्या है?

A. 00100 B. 00011 C. 00101 D. 11100

उत्तर: A

A सही है: 01001+11010=1 00011; carry fold करने से 00100=4।

B गलत है: carry वापस जोड़ने के बजाय छोड़ दिया।

C गलत है: raw sum के बाद एक के बजाय दो जोड़े।

D गलत है: इस representation में 11100 का मान −3 है।

C04. Zero canonicalization के बिना पाँच-bit one's-complement 6+(−6) का raw result क्या है?

A. 10000 B. 00001 C. 00000 D. 11111

उत्तर: D

A गलत है: यह sign-magnitude negative zero है, बताया raw addition नहीं।

B गलत है: fold या increment करने को carry नहीं निकला।

C गलत है: यह canonical zero है, पूछा raw sum नहीं।

D सही है: 00110+11001=11111, negative-zero pattern।

C05. छह-bit one's complement कितने अलग numerical integer values दर्शाता है?

A. 64 B. 63 C. 62 D. 32

उत्तर: B

A गलत है: 64 patterns हैं, जिनमें zero के दो हैं।

B सही है: −31…31 में 31+1+31=63 मान हैं।

C गलत है: numerical zero को पूरी तरह छोड़ दिया।

D गलत है: positive और negative दोनों nonzero values हैं।

C06. पाँच-bit sign-magnitude arithmetic में −11+(−7) का exact outcome क्या है?

A. −2 क्योंकि केवल low magnitude bits मायने रखते हैं B. +18, representable C. Overflow: −18 representable सीमा से बाहर है। D. Negative zero क्योंकि signs समान हैं

उत्तर: C

A गलत है: magnitude truncation exact योग नहीं देता।

B गलत है: sign negative है और magnitude 18, 15 से अधिक है।

C सही है: exact योग −18 है, लेकिन सीमा −15…15 है।

D गलत है: समान negative signs में magnitudes जुड़ते हैं, cancellation नहीं।

सीमा और स्रोत

यह Digital Logic के एक सीमित हिस्से का पाठ है, पूरे GATE CS की तैयारी नहीं। आधिकारिक पाठ्यक्रम केवल विषय की प्रासंगिकता की पुष्टि करता है; व्युत्पत्तियाँ, उदाहरण और अभ्यास मौलिक हैं। तकनीकी संदर्भों से representation और circuit की conventions जाँची गई हैं; उनके अभ्यास प्रश्न नहीं दोहराए गए।

स्रोत 14 अक्टूबर 2026 को जाँचे गए।

प्रगति सहेजने के लिए साइन इन करें। साइन इन