Digital Logic
Number Systems
Master DEC ↔ BIN ↔ OCT ↔ HEX shortcuts and 2’s complement — most Digital Logic NATs start with a clean conversion.
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
| Base | Digits | GATE shortcut |
|---|---|---|
| Binary (2) | 0, 1 | Weights 1,2,4,8,16,32,64,128,… |
| Octal (8) | 0–7 | Group binary in 3s from LSB |
| Decimal (10) | 0–9 | Repeated ÷2 / ÷8 / ÷16 |
| Hex (16) | 0–9, A–F | Group 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₈
| Binary | Octal | Hex | Decimal |
|---|---|---|---|
| 0000 | 0 | 0 | 0 |
| 0001 | 1 | 1 | 1 |
| 0010 | 2 | 2 | 2 |
| 0011 | 3 | 3 | 3 |
| 0100 | 4 | 4 | 4 |
| 0101 | 5 | 5 | 5 |
| 0110 | 6 | 6 | 6 |
| 0111 | 7 | 7 | 7 |
| 1000 | 10 | 8 | 8 |
| 1001 | 11 | 9 | 9 |
| 1010 | 12 | A | 10 |
| 1011 | 13 | B | 11 |
| 1100 | 14 | C | 12 |
| 1101 | 15 | D | 13 |
| 1110 | 16 | E | 14 |
| 1111 | 17 | F | 15 |
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
| Encoding | How to negate | Zero |
|---|---|---|
| Signed magnitude | Flip sign bit | +0 and −0 |
| 1’s complement | Bitwise NOT | +0 and −0 |
| 2’s complement | NOT then +1 | Single 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.
10 GATE-style MCQs for Number Systems with full explanations. Attempt each question before revealing the answer.
The 2’s complement of (−15)₁₀ in 6 bits is:
Show answer & explanation
Answer: A
15=001111 → invert 110000 → +1 → 110001.
Unsigned 8-bit maximum value is:
Show answer & explanation
Answer: C
2^8 − 1 = 255.
Hex 0x2F in binary is:
Show answer & explanation
Answer: A
2=0010, F=1111 → 00101111.
In 4-bit 2’s complement, which addition overflows?
Show answer & explanation
Answer: B
7+1=8 not representable in 4-bit 2’s (max 7).
BCD for decimal 29 uses how many bits?
Show answer & explanation
Answer: C
Two digits × 4 bits = 8 (0010 1001).
Decimal value of 8-bit 2’s complement 11100101 is:
Show answer & explanation
Answer: A
Negative; magnitude via 2’s of pattern → 27 ⇒ −27.
Binary 1011 to Gray code is:
Show answer & explanation
Answer: A
1, 1⊕0=1, 0⊕1=1, 1⊕1=0 → 1110.
Range of 5-bit 2’s complement integers is:
Show answer & explanation
Answer: A
−2^{4} … 2^{4}−1 = −16…15.
Octal 75 in binary is:
Show answer & explanation
Answer: A
7=111, 5=101 → 111101.
Excess-3 code for decimal digit 6 is:
Show answer & explanation
Answer: B
6+3=9 → 1001.
Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.
0xC3 in decimal is:
Show answer & explanation
Answer: A) 195
12×16+3=195.
8-bit 2’s complement of −1 is:
Show answer & explanation
Answer: C) 11111111
All ones represent −1 in 2’s complement.
Carry into sign ≠ carry out means:
Show answer & explanation
Answer: B) Signed overflow
Classic 2’s complement overflow test.
Binary 1110 as unsigned decimal is:
Show answer & explanation
Answer: B) 14
8+4+2=14 unsigned.
Minimum bits to represent −20 in 2’s complement:
Show answer & explanation
Answer: B) 6
5-bit range only to −16; 6-bit reaches −32…31.
BCD 0100 0111 represents decimal:
Show answer & explanation
Answer: A) 47
Digits 4 and 7.
Gray 0111 to binary is:
Show answer & explanation
Answer: B) 0101
b3=0; b2=0⊕1=1; b1=1⊕1=0; b0=0⊕1=1 → 0101.
200₁₀ in hex is:
Show answer & explanation
Answer: A) 0xC8
12×16+8=200.
4-bit unsigned 1111 + 0001 yields (mod 16):
Show answer & explanation
Answer: A) 0000 with carry
15+1 wraps to 0 in 4-bit unsigned.
Which code is invalid BCD?
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.
Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.