Skip to main content

Digital Logic

Number Systems

Master DEC ↔ BIN ↔ OCT ↔ HEX shortcuts and 2’s complement — most Digital Logic NATs start with a clean conversion.

~2 hrs ~0.5–1 mark · Must-score 10 samples · 10 practice · 10 cards

GATE CSE number systems — dec/bin/oct/hex conversions with exam tricks, 1’s and 2’s complement arithmetic, overflow, BCD/Gray, samples and drills.

Learning outcomes

  • Convert any integer among decimal, binary, octal, and hexadecimal using GATE-speed methods
  • Use 3-bit (octal) and 4-bit (hex) grouping tricks without long division every time
  • Represent negatives in 1’s / 2’s complement and detect signed overflow
  • Handle BCD, Excess-3, and Gray-code conversions at GATE depth

Positional number systems

  • Value = Σ digit_i × r^i for integer part (and × r^{−k} for fractions). Bases used in GATE: r = 2, 8, 10, 16.
  • Unsigned n-bit range: 0 … 2^n − 1. Always write the bit-width before a NAT.
  • Hex digits: 0–9, A=10, B=11, C=12, D=13, E=14, F=15. Never treat “A7” as decimal A×10.
  • Powers to memorise: 2^10=1024≈10^3, 2^8=256, 2^7=128, 2^4=16, 16^2=256, 16^3=4096.

Formulas to remember

  • Unsigned max (n bits) = 2^n − 1
  • Octal digit ↔ 3 bits; Hex digit ↔ 4 bits
  • N₁₀ = Σ d_i × r^i
BaseDigitsGATE shortcut
Binary (2)0, 1Weights 1,2,4,8,16,32,64,128,…
Octal (8)0–7Group binary in 3s from LSB
Decimal (10)0–9Repeated ÷2 / ÷8 / ÷16
Hex (16)0–9, A–FGroup binary in 4s from LSB

Worked example

Problem. Express 0xA7 in binary and decimal.

Solution. A=1010, 7=0111 → 10100111₂. Decimal: 10×16 + 7 = 167.

Decimal ↔ Binary

  • Decimal → binary (integer): repeatedly divide by 2; remainders bottom-up form the bits (LSB is first remainder).
  • Binary → decimal: sum weights of 1-bits. For 8-bit patterns, memorise 128 64 32 16 | 8 4 2 1.
  • Decimal → binary (fraction): multiply fraction by 2; integer parts top-down are bits after the point (GATE rarely goes beyond 4–6 bits).
  • Quick check: even decimal ⇒ LSB = 0; odd ⇒ LSB = 1. Use this to catch MCQ traps.

Formulas to remember

  • Integer: remainders of ÷2 from LSB to MSB
  • Fraction: ×2 integer bits from MSB of fraction toward finer bits

Worked example

Problem. Convert 45₁₀ to binary and 101101₂ to decimal.

Solution. 45÷2 → rem 1,0,1,1,0,1 → 101101₂. Weights: 32+8+4+1 = 45. Same pattern both ways.

Binary ↔ Octal ↔ Hex (grouping tricks)

  • Binary → octal: pad left with 0s to a multiple of 3, then map each 3-bit group (000=0 … 111=7). Always group from the LSB / binary point.
  • Binary → hex: pad to a multiple of 4; map each nibble (0000=0 … 1111=F). From LSB / binary point.
  • Octal → binary: replace every octal digit by its 3-bit code. Hex → binary: replace every hex digit by its 4-bit code. Never expand “digit by digit into decimal” unless asked.
  • Octal ↔ hex: convert via binary (octal→bin→hex). Direct octal↔hex without binary is error-prone under time pressure.
  • Leading zeros in padded groups do not change value — keep them only while grouping, drop after if the question wants a minimal string.

Formulas to remember

  • 3 bits ↔ 1 octal digit
  • 4 bits ↔ 1 hex digit
  • Example map: 1011₂ = B₁₆; 111₂ = 7₈
BinaryOctalHexDecimal
0000000
0001111
0010222
0011333
0100444
0101555
0110666
0111777
10001088
10011199
101012A10
101113B11
110014C12
110115D13
111016E14
111117F15

Worked example

Problem. Convert 110101101₂ to octal and hex.

Solution. 9 bits. Octal (groups of 3 from LSB): 110 101 101 → 655₈. Hex (pad to 12 bits): 0001 1010 1101 → 1AD₁₆.

Decimal ↔ Octal / Hex

  • Decimal → octal: repeated ÷8; remainders bottom-up. Decimal → hex: repeated ÷16; remainders 10–15 written as A–F.
  • Octal / hex → decimal: expand as Σ digit × base^position. For hex, treat A–F as 10–15.
  • GATE speed path: often Decimal → Binary (÷2) then group to octal/hex is faster than ÷8/÷16 if you know powers of 2.
  • Common trap: mixing 0x prefix with decimal arithmetic (e.g. reading 0x10 as ten). Always convert first.

Formulas to remember

  • N₈ = Σ o_i × 8^i
  • N₁₆ = Σ h_i × 16^i (A=10…F=15)

Worked example

Problem. Convert 200₁₀ to hex and octal.

Solution. ÷16: 200→12 rem 8, 12→0 rem C → 0xC8. Via binary 11001000 → groups 11 001 000 → 310₈; hex nibbles 1100 1000 → C8₁₆.

GATE exam tricks — number systems

  • Group from the right (LSB). Wrong grouping direction is the #1 conversion error in MCQs.
  • If options are hex/octal, convert the given binary by grouping — skip decimal unless needed for a numerical answer type.
  • Same bit string can mean different values: unsigned vs 2’s complement vs BCD. Read the encoding in the stem first.
  • For “minimum bits to represent N”: unsigned needs ceil(log₂(N+1)); 2’s complement negative −M needs enough bits so −2^{n−1} ≤ −M.
  • Fractions: 0.1₂ = 0.5₁₀, 0.01₂ = 0.25₁₀. GATE may ask exact binary of a terminating decimal like 0.625 = 0.101₂.
  • Shortcut: n hex digits ↔ 4n bits; n octal digits ↔ 3n bits. Use this for “how many bits?” questions.
  • BCD is not binary of the whole number — each decimal digit is coded separately (29 → 0010 1001, not 11101).
  • When comparing magnitudes across bases, convert all to decimal or to a common base — never compare digit strings of different bases.

Formulas to remember

  • Bits for unsigned 0…N → ⌈log₂(N+1)⌉
  • n hex digits = 4n bits; n octal digits = 3n bits

Worked example

Problem. How many bits are needed for unsigned integers 0 through 1000?

Solution. ⌈log₂(1001)⌉. 2^9=512, 2^10=1024 ≥ 1001 → 10 bits.

1’s and 2’s complement

  • 1’s complement: bitwise invert. 2’s complement: invert + 1 (or 2^n − x).
  • 2’s complement range on n bits: −2^{n−1} … 2^{n−1} − 1. One representation of zero.
  • Addition is ordinary binary add in the width; discard end carry outside n bits for modular wrap.
  • Overflow (signed): carry into sign ≠ carry out of sign, or two same-sign operands yield opposite-sign sum.
  • GATE trick: all-ones pattern in n-bit 2’s complement is always −1; MSB=1 means negative.

Formulas to remember

  • 2’s complement range = [−2^{n−1}, 2^{n−1} − 1]
  • 2’s complement(x) ≡ (2^n − x) mod 2^n
EncodingHow to negateZero
Signed magnitudeFlip sign bit+0 and −0
1’s complementBitwise NOT+0 and −0
2’s complementNOT then +1Single 0

Worked example

Problem. Represent −13 in 8-bit 2’s complement.

Solution. 13=00001101 → invert 11110010 → +1 → 11110011.

BCD, Excess-3, Gray code

  • BCD: each decimal digit → 4 bits 0000–1001. Invalid codes 1010–1111.
  • Excess-3: BCD + 0011 (self-complementing tricks appear in MCQs).
  • Gray code: consecutive codes differ by one bit — useful for K-map labeling and shaft encoders.
  • Binary→Gray: g_n=b_n, g_i=b_{i+1}⊕b_i. Gray→binary via cumulative XOR.

Worked example

Problem. 4-bit binary 1011 to Gray?

Solution. g3=1; g2=1⊕0=1; g1=0⊕1=1; g0=1⊕1=0 → 1110.

Exam tips

  • For bin↔oct/hex, always group from the LSB (or binary point) — never from the MSB of an unpadded string.
  • Prefer binary as the bridge: DEC→BIN→OCT/HEX is often faster than repeated ÷8/÷16 in the exam hall.
  • Memorise nibble↔hex (0–F) and 3-bit↔octal (0–7) tables; they kill most conversion MCQs in under 20 seconds.
  • Write bit-width on scrap paper before every complement NAT.
  • For overflow, check sign bits of operands and result — not merely “carry out”.
  • If the stem says BCD, code digits separately; if it says binary, convert the whole value.
  • Odd/even check: last binary bit must match decimal parity — instant option eliminator.
  • Count bits from hex/octal length: 3 hex digits ⇒ 12 bits; 4 octal digits ⇒ 12 bits.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for Number Systems with full explanations. Attempt each question before revealing the answer.

Q1 2’s complement conversion

The 2’s complement of (−15)₁₀ in 6 bits is:

  • A) 110001
  • B) 001111
  • C) 111111
  • D) 010001
Show answer & explanation

Answer: A

15=001111 → invert 110000 → +1 → 110001.

Q2 Unsigned range

Unsigned 8-bit maximum value is:

  • A) 127
  • B) 128
  • C) 255
  • D) 256
Show answer & explanation

Answer: C

2^8 − 1 = 255.

Q3 Hex conversion

Hex 0x2F in binary is:

  • A) 00101111
  • B) 00101110
  • C) 01001111
  • D) 101111
Show answer & explanation

Answer: A

2=0010, F=1111 → 00101111.

Q4 Signed overflow

In 4-bit 2’s complement, which addition overflows?

  • A) 3+2
  • B) 7+1
  • C) (−3)+(−2)
  • D) 1+(−1)
Show answer & explanation

Answer: B

7+1=8 not representable in 4-bit 2’s (max 7).

Q5 BCD width

BCD for decimal 29 uses how many bits?

  • A) 4
  • B) 5
  • C) 8
  • D) 16
Show answer & explanation

Answer: C

Two digits × 4 bits = 8 (0010 1001).

Q6 Signed interpretation

Decimal value of 8-bit 2’s complement 11100101 is:

  • A) −27
  • B) −26
  • C) 27
  • D) 229
Show answer & explanation

Answer: A

Negative; magnitude via 2’s of pattern → 27 ⇒ −27.

Q7 Gray conversion

Binary 1011 to Gray code is:

  • A) 1110
  • B) 1010
  • C) 0111
  • D) 1101
Show answer & explanation

Answer: A

1, 1⊕0=1, 0⊕1=1, 1⊕1=0 → 1110.

Q8 2’s complement range

Range of 5-bit 2’s complement integers is:

  • A) −16…15
  • B) −15…15
  • C) −32…31
  • D) 0…31
Show answer & explanation

Answer: A

−2^{4} … 2^{4}−1 = −16…15.

Q9 Octal conversion

Octal 75 in binary is:

  • A) 111101
  • B) 111100
  • C) 101111
  • D) 011101
Show answer & explanation

Answer: A

7=111, 5=101 → 111101.

Q10 Excess-3

Excess-3 code for decimal digit 6 is:

  • A) 0110
  • B) 1001
  • C) 0011
  • D) 1100
Show answer & explanation

Answer: B

6+3=9 → 1001.

Topic drill · 10 questions

10 practice questions — Number Systems

Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.

P1

0xC3 in decimal is:

  • A) 195
  • B) 201
  • C) 163
  • D) 207
Show answer & explanation

Answer: A) 195

12×16+3=195.

P2

8-bit 2’s complement of −1 is:

  • A) 00000001
  • B) 11111110
  • C) 11111111
  • D) 10000001
Show answer & explanation

Answer: C) 11111111

All ones represent −1 in 2’s complement.

P3

Carry into sign ≠ carry out means:

  • A) Parity error
  • B) Signed overflow
  • C) Always fine
  • D) BCD invalid
Show answer & explanation

Answer: B) Signed overflow

Classic 2’s complement overflow test.

P4

Binary 1110 as unsigned decimal is:

  • A) −2
  • B) 14
  • C) 7
  • D) 15
Show answer & explanation

Answer: B) 14

8+4+2=14 unsigned.

P5

Minimum bits to represent −20 in 2’s complement:

  • A) 5
  • B) 6
  • C) 7
  • D) 8
Show answer & explanation

Answer: B) 6

5-bit range only to −16; 6-bit reaches −32…31.

P6

BCD 0100 0111 represents decimal:

  • A) 47
  • B) 67
  • C) 4.7
  • D) Invalid
Show answer & explanation

Answer: A) 47

Digits 4 and 7.

P7

Gray 0111 to binary is:

  • A) 0100
  • B) 0101
  • C) 0010
  • D) 0111
Show answer & explanation

Answer: B) 0101

b3=0; b2=0⊕1=1; b1=1⊕1=0; b0=0⊕1=1 → 0101.

P8

200₁₀ in hex is:

  • A) 0xC8
  • B) 0xD8
  • C) 0xB8
  • D) 0xC0
Show answer & explanation

Answer: A) 0xC8

12×16+8=200.

P9

4-bit unsigned 1111 + 0001 yields (mod 16):

  • A) 0000 with carry
  • B) 1111
  • C) Overflow trap only
  • D) 0001
Show answer & explanation

Answer: A) 0000 with carry

15+1 wraps to 0 in 4-bit unsigned.

P10

Which code is invalid BCD?

  • A) 1001
  • B) 0110
  • C) 1010
  • D) 0000
Show answer & explanation

Answer: C) 1010

1010–1111 are unused in standard BCD digits.

Topic FAQs

What is the fastest DEC→HEX method in GATE?

Either repeated ÷16 with A–F remainders, or convert decimal→binary by ÷2 then group every 4 bits from the LSB. Use whichever you can do without mistakes under time pressure.

Why group from the LSB for octal/hex?

Place values align in 3-bit / 4-bit blocks from weight 2^0. Grouping from the MSB of an unpadded string shifts groups and yields a wrong digit string.

Can I convert octal directly to hex?

Yes via binary: expand each octal digit to 3 bits, regroup into 4-bit nibbles, map to hex. Avoid inventing a direct digit formula in the exam.

Why prefer 2’s complement in GATE machines?

Single zero, and addition/subtraction use the same adder hardware with modular arithmetic.

Is carry-out the same as overflow?

No. Unsigned wrap uses carry-out; signed overflow uses sign/carry-into-sign rules.

How do I avoid BCD vs binary traps?

Binary encodes the whole number; BCD encodes each decimal digit in 4 bits. 25₁₀ is 11001₂ but BCD 0010 0101.

Quick revision · 10 cards

10 flashcards — Number Systems

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 What is the unsigned maximum for n bits?
Q2 How do you form the 2’s complement of a pattern?
Q3 State the n-bit 2’s complement range.
Q4 When does 2’s complement addition overflow?
Q5 How many bits per decimal digit in BCD?
Q6 Binary → Gray rule?
Q7 Hex digit groups how many bits?
Q8 Why is there only one zero in 2’s complement?
Q9 Octal digit groups how many bits?
Q10 What is Excess-3 for digit d?