Conversion Between Number Systems

Converting numbers between binary, octal, decimal and hexadecimal, including negative numbers.

Conversion Between Number Systems

Number System Conversion (संख्या पद्धति रूपांतरण) का अर्थ है किसी संख्या को एक number system से दूसरे number system में बदलना, जैसे Decimal को Binary में, Binary को Decimal में, Decimal को Octal में या Hexadecimal को Binary में convert करना।

मुख्य Number Systems:
Decimal → Base 10
Binary → Base 2
Octal → Base 8
Hexadecimal → Base 16

Computer Science में number system conversion का विशेष महत्व है क्योंकि computer internally binary data पर कार्य करता है, जबकि मनुष्य सामान्यतः decimal system का उपयोग करता है।

Why Number System Conversion is Required?

अलग-अलग situations में अलग-अलग number systems उपयोगी होते हैं। इसलिए एक number system में दी गई संख्या को दूसरे number system में convert करना आवश्यक हो सकता है।

  • Human-readable values के लिए Decimal system उपयोगी है।
  • Computer internal representation के लिए Binary system उपयोगी है।
  • Binary numbers को compact रूप में लिखने के लिए Octal और Hexadecimal उपयोगी हैं।
  • Programming और computer systems में different representations को समझने के लिए conversion आवश्यक है।

Common Number System Conversions

Conversion Common Method
Decimal → Binary Repeated Division by 2
Decimal → Octal Repeated Division by 8
Decimal → Hexadecimal Repeated Division by 16
Binary → Decimal Positional Value Method
Octal → Decimal Positional Value Method
Hexadecimal → Decimal Positional Value Method
Binary → Octal Grouping into 3 bits
Octal → Binary Each digit into 3 bits
Binary → Hexadecimal Grouping into 4 bits
Hexadecimal → Binary Each digit into 4 bits

Decimal to Binary Conversion

Decimal number को Binary में convert करने के लिए Repeated Division by 2 method का उपयोग किया जाता है। संख्या को बार-बार 2 से divide किया जाता है और प्रत्येक division का remainder लिखा जाता है। अंत में remainders को नीचे से ऊपर की ओर पढ़ा जाता है।

Example: Decimal number 25 को Binary में convert करें।

Division Quotient Remainder
25 ÷ 2 12 1
12 ÷ 2 6 0
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1

Remainders को नीचे से ऊपर पढ़ने पर:

(25)10 = (11001)2

Decimal to Octal Conversion

Decimal number को Octal में convert करने के लिए संख्या को बार-बार 8 से divide किया जाता है। Remainders को नीचे से ऊपर पढ़ने पर Octal number प्राप्त होता है।

Example: Decimal number 83 को Octal में convert करें।

Division Quotient Remainder
83 ÷ 8 10 3
10 ÷ 8 1 2
1 ÷ 8 0 1

Remainders को नीचे से ऊपर पढ़ने पर:

(83)10 = (123)8

Decimal to Hexadecimal Conversion

Decimal number को Hexadecimal में convert करने के लिए संख्या को बार-बार 16 से divide किया जाता है। Remainders 0 से 9 तक होने पर वही digits और 10 से 15 तक होने पर A से F तक symbols का उपयोग किया जाता है।

Example: Decimal number 254 को Hexadecimal में convert करें।

Division Quotient Remainder
254 ÷ 16 15 14 (E)
15 ÷ 16 0 15 (F)

Remainders को नीचे से ऊपर पढ़ने पर:

(254)10 = (FE)16

Binary to Decimal Conversion

Binary number को Decimal में convert करने के लिए प्रत्येक binary digit को 2 की corresponding power से multiply किया जाता है और सभी values को add किया जाता है।

Example: Binary number 110101 को Decimal में convert करें।

(110101)₂

= 1 × 2⁵ + 1 × 2⁴ + 0 × 2³ + 1 × 2² + 0 × 2¹ + 1 × 2⁰

= 32 + 16 + 0 + 4 + 0 + 1

= 53
Answer: (110101)2 = (53)10

Octal to Decimal Conversion

Octal number को Decimal में convert करने के लिए प्रत्येक digit को 8 की corresponding power से multiply किया जाता है।

Example: Octal number 157 को Decimal में convert करें।

(157)₈

= 1 × 8² + 5 × 8¹ + 7 × 8⁰

= 1 × 64 + 5 × 8 + 7 × 1

= 64 + 40 + 7

= 111
Answer: (157)8 = (111)10

Hexadecimal to Decimal Conversion

Hexadecimal number को Decimal में convert करने के लिए प्रत्येक digit को 16 की corresponding power से multiply किया जाता है। Hexadecimal में A = 10, B = 11, C = 12, D = 13, E = 14 और F = 15 होता है।

Example: Hexadecimal number 2A को Decimal में convert करें।

(2A)₁₆

= 2 × 16¹ + A × 16⁰

= 2 × 16 + 10 × 1

= 32 + 10

= 42
Answer: (2A)16 = (42)10

Binary to Octal Conversion

Binary को Octal में convert करने के लिए binary digits को right side से 3-3 bits के groups में divide किया जाता है। प्रत्येक 3-bit group को उसके corresponding octal digit में convert किया जाता है।

Example: Binary number 101101 को Octal में convert करें।

Binary number:
101101

Group into 3 bits:
101 | 101

101 = 5
101 = 5

Therefore,

(101101)₂ = (55)₈
Answer: (101101)2 = (55)8

Binary to Octal Conversion with Padding

यदि binary digits की संख्या 3 के multiple में नहीं है, तो left side में आवश्यक number of zeros add किए जाते हैं।

Example: Binary number 1101 को Octal में convert करें।

1101

Add zero on the left:
001 | 101

001 = 1
101 = 5

Therefore,

(1101)₂ = (15)₈
Answer: (1101)2 = (15)8

Octal to Binary Conversion

Octal को Binary में convert करना बहुत आसान है। प्रत्येक octal digit को उसके 3-bit binary equivalent से replace किया जाता है।

Example: Octal number 57 को Binary में convert करें।

5 = 101
7 = 111

Therefore,

(57)₈ = (101111)₂
Answer: (57)8 = (101111)2

Binary to Hexadecimal Conversion

Binary number को Hexadecimal में convert करने के लिए binary digits को right side से 4-4 bits के groups में divide किया जाता है। प्रत्येक group को corresponding hexadecimal digit में convert किया जाता है।

Example: Binary number 10101111 को Hexadecimal में convert करें।

10101111

Group into 4 bits:
1010 | 1111

1010 = A
1111 = F

Therefore,

(10101111)₂ = (AF)₁₆
Answer: (10101111)2 = (AF)16

Binary to Hexadecimal Conversion with Padding

यदि binary number के digits 4 के multiple में नहीं हैं, तो left side में zeros add करके 4-bit groups बनाए जाते हैं।

Example: Binary number 110101 को Hexadecimal में convert करें।

110101

Add zeros on the left:
0011 | 0101

0011 = 3
0101 = 5

Therefore,

(110101)₂ = (35)₁₆
Answer: (110101)2 = (35)16

Hexadecimal to Binary Conversion

Hexadecimal number को Binary में convert करने के लिए प्रत्येक hexadecimal digit को उसके 4-bit binary equivalent से replace किया जाता है।

Example: Hexadecimal number 3C को Binary में convert करें।

3 = 0011
C = 1100

Therefore,

(3C)₁₆ = (00111100)₂
Answer: (3C)16 = (00111100)2

Octal to Hexadecimal Conversion

Octal से Hexadecimal में direct conversion के बजाय पहले Octal को Binary में और फिर Binary को Hexadecimal में convert करना आसान होता है।

Example: Octal number 57 को Hexadecimal में convert करें।

Step 1: Octal to Binary

5 = 101
7 = 111

(57)₈ = (101111)₂

Step 2: Binary to Hexadecimal

101111
= 0010 | 1111
= 2 | F

Therefore,

(57)₈ = (2F)₁₆
Answer: (57)8 = (2F)16

Hexadecimal to Octal Conversion

Hexadecimal से Octal में conversion के लिए पहले Hexadecimal को Binary में और फिर Binary को Octal में convert किया जा सकता है।

Example: Hexadecimal number 2F को Octal में convert करें।

Step 1: Hexadecimal to Binary

2 = 0010
F = 1111

(2F)₁₆ = (00101111)₂

Step 2: Binary to Octal

00101111
= 000 | 101 | 111
= 0 | 5 | 7

Leading zero is removed.

Therefore,

(2F)₁₆ = (57)₈
Answer: (2F)16 = (57)8

Conversion Table: Binary, Octal and Hexadecimal

Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Number System Conversion in C++

C++ में decimal integer को binary, octal और hexadecimal form में display करने के लिए bitset तथा output manipulators का उपयोग किया जा सकता है।

Example: एक decimal number को Binary, Octal और Hexadecimal form में display करना:

#include <iostream>
#include <bitset>
using namespace std;

int main()
{
    int n = 25;

    cout << "Decimal: " << n << endl;
    cout << "Binary: " << bitset<8>(n) << endl;

    cout << "Octal: " << oct << n << endl;
    cout << "Hexadecimal: " << hex << n << endl;

    return 0;
}
Output:
Decimal: 25
Binary: 00011001
Octal: 31
Hexadecimal: 19

यहाँ oct integer को octal form में और hex integer को hexadecimal form में display करता है। bitset<8> number को 8-bit binary representation में दिखाता है।

Important Points

  • Decimal से Binary conversion में division by 2 किया जाता है।
  • Decimal से Octal conversion में division by 8 किया जाता है।
  • Decimal से Hexadecimal conversion में division by 16 किया जाता है।
  • Binary से Decimal conversion में powers of 2 का उपयोग किया जाता है।
  • Octal से Decimal conversion में powers of 8 का उपयोग किया जाता है।
  • Hexadecimal से Decimal conversion में powers of 16 का उपयोग किया जाता है।
  • Binary से Octal conversion में 3-3 bits के groups बनाए जाते हैं।
  • Octal से Binary conversion में प्रत्येक digit को 3 bits में बदला जाता है।
  • Binary से Hexadecimal conversion में 4-4 bits के groups बनाए जाते हैं।
  • Hexadecimal से Binary conversion में प्रत्येक digit को 4 bits में बदला जाता है।
  • Grouping करते समय आवश्यकता होने पर left side में zeros add किए जाते हैं।
  • Hexadecimal में A, B, C, D, E और F क्रमशः 10, 11, 12, 13, 14 और 15 को represent करते हैं।

Board Focus

Exam के लिए याद रखें:
Decimal → Binary → Divide by 2
Decimal → Octal → Divide by 8
Decimal → Hexadecimal → Divide by 16
Binary → Octal → 3-bit grouping
Binary → Hexadecimal → 4-bit grouping
Octal → Binary → 1 digit = 3 bits
Hexadecimal → Binary → 1 digit = 4 bits

Board Important Questions

Very Short Answer Questions

Q1. Decimal number को Binary में convert करने के लिए किस method का उपयोग किया जाता है?

Answer: Repeated Division by 2 method का उपयोग किया जाता है।

Q2. Decimal number को Octal में convert करने के लिए किस संख्या से divide किया जाता है?

Answer: 8 से divide किया जाता है।

Q3. Decimal number को Hexadecimal में convert करने के लिए किस संख्या से divide किया जाता है?

Answer: 16 से divide किया जाता है।

Q4. Binary से Octal conversion में कितने bits का group बनाया जाता है?

Answer: 3 bits का group बनाया जाता है।

Q5. Binary से Hexadecimal conversion में कितने bits का group बनाया जाता है?

Answer: 4 bits का group बनाया जाता है।

Q6. Hexadecimal में A का decimal value क्या है?

Answer: 10

Short Answer Questions

Q7. Decimal number 25 को Binary में convert कीजिए।

25 ÷ 2 = 12 remainder 1
12 ÷ 2 = 6  remainder 0
6 ÷ 2  = 3  remainder 0
3 ÷ 2  = 1  remainder 1
1 ÷ 2  = 0  remainder 1

Reading remainders from bottom to top:

(25)₁₀ = (11001)₂

Q8. Binary number 10101 को Decimal में convert कीजिए।

(10101)₂
= 1 × 2⁴ + 0 × 2³ + 1 × 2² + 0 × 2¹ + 1 × 2⁰
= 16 + 0 + 4 + 0 + 1
= 21
Answer: (10101)₂ = (21)₁₀

Q9. Binary 110101 को Octal में convert कीजिए।

110101
= 110 | 101

110 = 6
101 = 5

Therefore,

(110101)₂ = (65)₈
Answer: (110101)₂ = (65)₈

Q10. Binary 10101111 को Hexadecimal में convert कीजिए।

10101111
= 1010 | 1111

1010 = A
1111 = F

Therefore,

(10101111)₂ = (AF)₁₆
Answer: (10101111)₂ = (AF)₁₆

Long Answer Questions

Q11. Decimal number 156 को Binary, Octal और Hexadecimal में convert कीजिए।

Decimal to Binary:

156 ÷ 2 = 78 remainder 0
78 ÷ 2  = 39 remainder 0
39 ÷ 2  = 19 remainder 1
19 ÷ 2  = 9  remainder 1
9 ÷ 2   = 4  remainder 1
4 ÷ 2   = 2  remainder 0
2 ÷ 2   = 1  remainder 0
1 ÷ 2   = 0  remainder 1

(156)₁₀ = (10011100)₂

Decimal to Octal:

156 ÷ 8 = 19 remainder 4
19 ÷ 8  = 2  remainder 3
2 ÷ 8   = 0  remainder 2

(156)₁₀ = (234)₈

Decimal to Hexadecimal:

156 ÷ 16 = 9 remainder 12 (C)
9 ÷ 16   = 0 remainder 9

(156)₁₀ = (9C)₁₆
Answer:
(156)₁₀ = (10011100)₂ = (234)₈ = (9C)₁₆

Q12. Binary number 11101101 को Decimal, Octal और Hexadecimal में convert कीजिए।

Binary to Decimal:

(11101101)₂
= 1×2⁷ + 1×2⁶ + 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 128 + 64 + 32 + 0 + 8 + 4 + 0 + 1
= 237

Binary to Octal:

11101101
= 011 | 101 | 101

011 = 3
101 = 5
101 = 5

Therefore,

(11101101)₂ = (355)₈

Binary to Hexadecimal:

11101101
= 1110 | 1101

1110 = E
1101 = D

Therefore,

(11101101)₂ = (ED)₁₆
Answer:
(11101101)₂ = (237)₁₀ = (355)₈ = (ED)₁₆

Quick Revision

  • Decimal → Binary: Divide by 2
  • Decimal → Octal: Divide by 8
  • Decimal → Hexadecimal: Divide by 16
  • Binary → Decimal: Powers of 2
  • Octal → Decimal: Powers of 8
  • Hexadecimal → Decimal: Powers of 16
  • Binary → Octal: 3-bit grouping
  • Binary → Hexadecimal: 4-bit grouping
  • Octal → Binary: Each digit = 3 bits
  • Hexadecimal → Binary: Each digit = 4 bits
One-Line Revision: Number system conversion में किसी संख्या को एक base से दूसरे base में बदला जाता है; Decimal conversion में division method और Binary conversion में positional तथा grouping methods का उपयोग किया जाता है।

Practice Questions

  1. Decimal number 45 को Binary में convert कीजिए।
  2. Decimal number 75 को Octal में convert कीजिए।
  3. Decimal number 125 को Hexadecimal में convert कीजिए।
  4. Binary number 101101 को Decimal में convert कीजिए।
  5. Binary number 11001101 को Octal में convert कीजिए।
  6. Binary number 11110010 को Hexadecimal में convert कीजिए।
  7. Octal number 157 को Decimal में convert कीजिए।
  8. Octal number 75 को Binary में convert कीजिए।
  9. Hexadecimal number 2F को Decimal में convert कीजिए।
  10. Hexadecimal number 3A को Binary में convert कीजिए।
  11. Decimal number 200 को Binary, Octal और Hexadecimal में convert कीजिए।
  12. Binary number 10101010 को Decimal, Octal और Hexadecimal में convert कीजिए।
  13. Binary to Octal और Binary to Hexadecimal conversion में grouping का क्या नियम है?
  14. Number system conversion में padding zero का क्या उपयोग है?
  15. Decimal, Binary, Octal और Hexadecimal के बीच conversion methods को उदाहरण सहित समझाइए।
Lesson 33 of 39
On This Page