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

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

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

Binary fractions और fixed-point arithmetic

पाठ 51 / 748 मिनटमुफ़्त

Binary point एक scale convention है

Radix point के दाएँ binary positions के भार 2^−1,2^−2,2^−3,… हैं। इसलिए (10.101)₂=2+1/2+1/8=2.625। Dot पढ़ने की convention है, अतिरिक्त stored bit नहीं। Scale बताने पर stored integer से fraction दर्शा सकते हैं।

पूर्वज्ञान: unsigned binary और two's-complement signed integers। लक्ष्य: terminating binary fractions बदलना, scaled integer decode करना, range/resolution निकालना और सही scale तथा rounding के साथ जोड़/गुणा करना। पहले mathematical arithmetic और फिर स्पष्ट storage rule लगाएँगे; programming language की implicit conversion नहीं मानते।

n-bit signed fixed-point format में f fractional bits होने का अर्थ value I×2^−f है, जहाँ I n-bit two's-complement integer और f≥0 स्थिर है। n तथा f सीधे बताते हैं क्योंकि Q-format की naming conventions sign/integer bits अलग गिन सकती हैं। Stored values समान अंतर पर हैं; f बदलने से interpretation बदलती है, stored bits की संख्या नहीं।

Fraction को बदलें

0≤r<1 वाले fraction को बार-बार 2 से गुणा करें। Integer part बाएँ से अगला bit है; बचा fractional part अगले चरण में लें।

हल किया उदाहरण 1: 0.6875×2=1.375 से bit 1 और remainder 0.375; फिर 0.375×2=0.75 से bit 0; 0.75×2=1.5 से bit 1; 0.5×2=1 से bit 1 और zero remainder। अतः 0.6875=(0.1011)₂। जाँच: 1/2+1/8+1/16=11/16।

Reduced rational p/q की binary fractional expansion finite ठीक तब है जब q दो की घात हो। हर finite expansion किसी integer/2^f के बराबर है; और ऐसा denominator पर्याप्त fractional positions में लिखा जा सकता है। Decimal 0.1=1/10 के reduced denominator में factor 5 है, इसलिए कोई finite binary fraction उसे exact नहीं दर्शाता। अधिक bits approximation सुधारते हैं, इस rational को exact नहीं बनाते।

Range resolution और decoding

Scaled signed range −2^(n−1−f) से 2^(n−1−f)−2^−f तक और resolution Δ=2^−f है। Resolution पास के stored values का अंतर है, हर मान के लिए relative-error guarantee नहीं। समान total width में fractional bits बढ़ाने से resolution सुधरती है लेकिन range घटती है।

n=8,f=4 में integer range −128…127 बदलकर −8…7.9375 होती है और Δ=1/16=0.0625। कुल 256 encodings और एक zero है। Pattern 10000000 का मान −8 है, negative zero नहीं।

हल किया उदाहरण 2: n=8,f=4 पर 11011010 decode करें। Unsigned value 218 है, इसलिए signed I=218−256=−38। Scale लगाने पर −38/16=−2.375। Top bit को अलग minus sign न बनाएँ और scale केवल positive bits पर न लगाएँ।

हल किया उदाहरण 3: इसी format में 1.3125 encode करें। 16 से गुणा: I=21, जो integer है और range में है। Store 00010101। −1.3125 के लिए signed integer −21 का pattern 11101011 लें। वापस decode करके जाँचें। मनमाने x के लिए x×2^f निकालें, जरूरत पर बताया integer-rounding rule लगाएँ और storage से पहले integer range जाँचें।

Rounding भी शर्त का हिस्सा है

x=0.1,f=4 लें। Scaled x=1.6 है, इसलिए nearest rounding में I=2 और stored value 0.125। Error यानी stored minus exact, +0.025 है। Toward-zero rounding I=1 और 0.0625 देती। इस scale में दोनों में से कोई 0.1 exact नहीं लिखती।

Nearest rounding में tie दो पास के मानों के ठीक बीच है। Ties-to-even में वह candidate चुनते हैं जिसका scaled integer I even है; decimal spelling के अंतिम अंक का even होना नियम नहीं। जैसे x=0.09375 से scaled 1.5, यानी I=1 और I=2 का midpoint। I=2 चुनें, value 0.125। Range overflow न होने पर nearest rounding का absolute error अधिकतम Δ/2 है। Tie में दोनों पड़ोसियों का error magnitude समान है; even rule दिशा चुनता है।

Truncation की परिभाषा भी जरूरी है। f=4 में −0.1 को toward-zero करने पर I=−1 और −0.0625 मिलता है। Downward rounding I=−2 और −0.125 देती है। Signed shift में low bits हटाना अपने आप toward-zero rounding नहीं है। Machine instruction का व्यवहार बिना बताए न लागू करें।

जोड़ में समान scale चाहिए

दोनों values का f समान हो तो raw integers जोड़ सकते हैं: (I_a+I_b)2^−f। Destination width की integer सीमा जाँचें। Scales अलग हों तो पहले common scale में बदलें; rounding और अतिरिक्त bits की जरूरत हो सकती है। अलग scales वाले raw integers सीधे जोड़ना सामान्यतः अर्थहीन है।

हल किया उदाहरण 4: n=8,f=4 में 1.5 का I=24 और 2.25 का I=36। 24+36=60 जोड़ें; 60/16=3.75। Rounding नहीं चाहिए और 60 समाता है।

इसके विपरीत 7.5+0.75 में I values 120,12 हैं और exact I=132, जो 127 से बड़ा है। Exact 8.25 format से बाहर है। केवल यदि policy low आठ bits रखने को कहती हो, तो 10000100 से I=−124 और value −7.75 मिलेगा। Saturation में 7.9375 रखा जाएगा। Overflow flag, wraparound result और saturated result अलग चीजें हैं; format अकेले policy नहीं चुनता।

गुणा में scale बदलती है

Exact product (I_a I_b)2^−2f है। Rescaling से पहले 2f fractional bits हैं। दो n-bit signed integers का full product, 2n signed bits में समा सकता है। वापस f पर आने के लिए product integer को 2^f से बताए rounding rule के साथ भाग दें, फिर range जाँचें।

हल किया उदाहरण 5: n=8,f=4 में 1.5×(−2) के लिए 24×(−32)=−768। Scale 2^−8 पर इसका मान −3 है। f=4 लौटने के लिए −768/16=−48 exact मिलता है, जिसका stored pattern 11010000 है।

हल किया उदाहरण 6: 1.25×1.125 में I_a=20,I_b=18, raw product 360 और exact value 360/256=1.40625। f=4 पर scaled integer 22.5 है। Nearest ties-to-even, I=22 चुनता है, इसलिए stored 22/16=1.375। I=23 से 1.4375 मिलता, जो उतना ही पास है लेकिन scaled integer odd है। यह rounding loss है, range overflow नहीं।

मुख्य जाँचें

Total width, signed encoding, fractional-bit count, rounding और overflow policy लिखें। Scaling से पहले raw integer decode करें। जोड़ से पहले scales align और गुणा में fractional-bit counts जोड़ें; intermediate width पर्याप्त रखें। Exact representability और range अलग जाँचें: range के अंदर की value को भी rounding लग सकती है।

मौलिक अभ्यास

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

C01. Binary (11.011)₂ का decimal मान क्या है?

A. 3.75 B. 3.375 C. 3.125 D. 3.011

उत्तर: B

A गलत है: .11₂=.75 है; दिया fraction .011₂ है।

B सही है: 2+1+1/4+1/8=3.375।

C गलत है: 1/4 वाला स्थान छूट गया।

D गलत है: binary fraction के digits decimal digits नहीं।

C02. आठ-bit two's-complement fixed-point format में f=4 है। न्यूनतम और अधिकतम क्या हैं?

A. −128 और 127 B. −8 और 8 C. −7.9375 और 7.9375 D. −8 और 7.9375

उत्तर: D

A गलत है: ये 16 से भाग से पहले raw integer limits हैं।

B गलत है: +8 के लिए raw I=128 चाहिए, जो नहीं समाता।

C गलत है: raw I=−128 से −8 representable है।

D सही है: −128 और 127 को 16 से भाग दें।

C03. f=3 वाले आठ-bit two's-complement fixed-point format में 11101000 decode करें।

A. −3 B. 29 C. −13 D. −24

उत्तर: A

A सही है: signed integer 232−256=−24 और 1/8 scale से −3।

B गलत है: unsigned 232/8=29 में signedness छूट गई।

C गलत है: sign bit को अलग magnitude माना है।

D गलत है: −24 scaling से पहले raw integer है।

C04. किस decimal fraction की finite binary expansion नहीं है?

A. 0.625 B. 0.125 C. 0.1 D. 0.75

उत्तर: C

A गलत है: 0.625=5/8 terminate होता है।

B गलत है: 0.125=1/8 terminate होता है।

C सही है: 1/10 के reduced denominator में factor 5 है।

D गलत है: 0.75=3/4 terminate होता है।

C05. पर्याप्त range में x=0.15625 को f=4 fixed-point में nearest ties-to-even से round करें। क्या store होगा?

A. 0.1875 B. 0.125 C. 0.15625 exact D. 0.0625

उत्तर: B

A गलत है: इस tie में scaled I=3 odd है।

B सही है: x×16=2.5; even I=2 से 0.125 चुनें।

C गलत है: scaled 2.5 कोई integer encoding नहीं।

D गलत है: I=1 nearest candidate नहीं।

C06. दो fixed-point operands में f=5 fractional bits हैं। Rescaling से पहले raw product में कितने fractional bits हैं?

A. 5 B. 25 C. 6 D. 10

उत्तर: D

A गलत है: गुणा में दोनों scales मिलती हैं, केवल एक नहीं।

B गलत है: fractional-bit counts जुड़ते हैं, गुणा नहीं होते।

C गलत है: एक bit बढ़ना कुछ sum widths से जुड़ा है, इस product scale से नहीं।

D सही है: 2^−5×2^−5=2^−10, इसलिए दस fractional bits।

सीमा और स्रोत

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

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

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