CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 0 · Foundations

Lesson 0.2.2 · Item 5 of 90

Binary, decimal and hex; powers of 2

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. How many bits are in 2 KB?
    Stuck? Peek at 0.2.1 Bits, bytes and prefixes: powers of 10 for rates, powers of 2 for sizes
    • 1 B = 8 b. Lower-case b = bit, upper-case B = byte.
    • Rates: k = 10³, M = 10⁶, G = 10⁹ (bps).
    • Sizes: K = 2¹⁰, M = 2²⁰, G = 2³⁰ (bytes) — unless the question says 1000.
    • Time to push out = (size in bits) ÷ (rate in bit/s).
    • ms = 10⁻³ s, µs = 10⁻⁶ s, ns = 10⁻⁹ s.

    Read lesson 0.2.1

  2. Mesh vs star: links for n nodes?
    Stuck? Peek at 0.1.2 Nodes, links, topologies, LAN/WAN and the boxes in the middle
    • Node = any device; host = node where messages start/end.
    • Point-to-point (2 nodes) vs broadcast (all hear all).
    • Simplex (one way) · half-duplex (two ways, one at a time) · full-duplex (both at once).
    • Links: mesh n(n−1)/2, star n, ring n, tree n−1, bus 1 backbone.
    • LAN (building) ⊂ WAN (cities) ⊂ the Internet (network of networks).
    • Hub repeats to all · switch delivers within a LAN · router picks the next network.

    Read lesson 0.1.2

  3. Where does the meaning of a bit pattern come from?
    Stuck? Peek at 0.1.1 Why networks exist: hosts, links and sending data
    • Network = devices + links that exchange data.
    • Host = where a message starts or ends (laptop, phone, server).
    • Link = physical path: copper (voltage), fibre (light), wireless (radio).
    • All content → bits → signals → bits → content; meaning comes from an agreed encoding.
    • One link per pair of n hosts: n(n − 1)/2 links — too many, so links are shared.

    Read lesson 0.1.1

The Hook

Every address, every length and every counter inside a network is a binary number stored in a fixed number of bits. Read the field wrong by one bit and you are off by a factor of two. Engineers write those numbers in hexadecimal because four bits fit exactly in one hex digit. Fluency here pays off in every phase that follows.

Predict First

A counter is stored in 8 bits. Guess the largest number it can hold: 8, 128, 255 or 256?

,

255. 8 bits give 2⁸ = 256 different patterns, from 00000000 (0) to 11111111 (255). The count of patterns is 256; the largest value is one less.

Core Concept

Place value

Decimal: each place is worth 10 times the place to its right (1, 10, 100…). Binary is the same idea with 2: places are worth 1, 2, 4, 8, 16, 32, 64, 128…

Binary number bk−1…b1b0 has value Σ bi × 2i. The leftmost bit is the MSB (most significant bit), the rightmost the LSB (least significant bit).
Place2⁷2⁶2⁵2⁴2³2²2¹2⁰
Worth1286432168421
1100100011001000
11001000 = 128 + 64 + 8 = 200.

Decimal → binary

Method: subtract the largest power of 2 that fits, mark a 1 in that place, repeat. Or divide by 2 repeatedly and read the remainders from bottom to top.

Worked visual sequence

The supplied notes include an interactive visual for this concept; this reading view preserves the surrounding explanation and sequence.

Repeated division by 2.

Hexadecimal

Hex is base 16. Digits 0–9 then A=10, B=11, C=12, D=13, E=14, F=15. One hex digit = exactly 4 bits (a "nibble"), so binary ↔ hex is just grouping in fours from the right. Hex is often written with a prefix: 0xC8.

110010001100 = C1000 = 8
11001000 → group in fours → C8. So 200 = 0xC8.

k bits give 2ᵏ values

With k bits there are 2ᵏ patterns, representing 0 to 2ᵏ − 1. To count N different things you need the smallest k with 2ᵏ ≥ N.

k2ᵏk2ᵏ
12101,024
24124,096
416138,192
82561665,536
9512201,048,576
324,294,967,296
Powers of 2 worth memorising up to 2¹⁶, plus 2²⁰ ≈ one million and 2³² ≈ 4.29 billion.

Putting it together

  • Binary is place value with powers of 2; hex groups 4 bits per digit.
  • k bits give 2ᵏ values, from 0 to 2ᵏ − 1.
  • Bits needed for N values is the smallest k with 2ᵏ ≥ N.

Visual

DecimalBinaryHex
000000
501015
910019
101010A
121100C
151111F
2001100 1000C8
2551111 1111FF
Conversion table: every hex digit is one group of four bits.

Worked Examples

Easy

Write 200 in binary (8 bits) and in hex.

Show the full solution

200 − 128 = 72 → 72 − 64 = 8 → 8 − 8 = 0. Places 128, 64 and 8 are 1: 11001000. Group: 1100 | 1000 = C | 8 → 0xC8.

Medium

Convert 10110110 to decimal and to hex.

Show the full solution

128 + 32 + 16 + 4 + 2 = 182. Groups 1011 | 0110 = B | 6 → 0xB6.

GATE

(a) Convert 0x3F7 to decimal. (b) A field must hold every integer from 0 to 5000. What is the minimum number of bits? (c) What is the largest value of a 13-bit field?

Show the full solution

(a) 3 × 256 + 15 × 16 + 7 = 768 + 240 + 7 = 1015.

(b) 0..5000 is 5001 values. 2¹² = 4096 < 5001 ≤ 8192 = 2¹³ → 13 bits.

(c) 2¹³ − 1 = 8191.

GATE Traps

  • k bits hold 2ᵏ values, but the largest value is 2ᵏ − 1.
  • "From 0 to 5000" is 5001 values, not 5000.
  • Group hex digits from the right (LSB end), not from the left.

Memory Hook

"One hex digit is one nibble": four bits, sixteen faces — 0 to F.

Connect the Dots

Binary numbers are how every field inside the network's wrappers will be stored. Next (0.2.3): networks also combine bit patterns — flipping, adding with a wrap-around, and dividing without carries. Those are the tools that will catch damaged bits in Phase 2.

Self-Test

  1. MCQ

    0xA5 in binary is:

    1. 10100101
    2. 10101010
    3. 01011010
    4. 11000101
  2. NAT

    Decimal value of 11110000?

    Write your answer before opening the key.

  3. NAT

    Minimum bits to give a different number to each of 1000 items?

    Write your answer before opening the key.

  4. MSQ

    Which are true for a 16-bit field?

    1. It has 65,536 possible values.
    2. Its largest value is 65,535.
    3. Its largest value in hex is 0xFFFF.
    4. It needs 4 hex digits plus one bit.
  5. NAT

    Decimal value of 0x1F4?

    Write your answer before opening the key.

Rule Card

  • Binary places: 1, 2, 4, 8, 16, 32, 64, 128, …; MSB left, LSB right.
  • Hex: one digit = 4 bits; A–F = 10–15; group from the right.
  • k bits → 2ᵏ values, 0 … 2ᵏ − 1.
  • Bits needed for N values = smallest k with 2ᵏ ≥ N.
  • 2¹⁰ = 1024 · 2¹⁶ = 65,536 · 2²⁰ ≈ 1.05 M · 2³² ≈ 4.29 × 10⁹.

Concept Ledger

  • binary
  • decimal
  • hexadecimal (hex), 0x prefix
  • place value
  • MSB / LSB
  • nibble (4 bits)
  • k bits give 2ᵏ values
  • powers of 2

Answer Vault

Try the questions first. Open when you are ready to check.

Warm-up answers

  1. 2 × 1024 × 8 = 16,384.
  2. Mesh n(n − 1)/2, star n.
  3. From an encoding agreed in advance by sender and receiver.

Self-test answers

  1. A — A = 1010, 5 = 0101 → 10100101.
    • B: That is 0xAA.
    • C: That is 0x5A (digits swapped).
    • D: That is 0xC5.
  2. 240 — 128 + 64 + 32 + 16 = 240.
  3. 10 — 2⁹ = 512 < 1000 ≤ 1024 = 2¹⁰ → 10 bits.
  4. ABC — 2¹⁶ = 65,536 values, 0 to 65,535 = 0xFFFF; 16 bits = exactly 4 hex digits.
    • D: 16 bits = 4 × 4 bits = exactly 4 hex digits.
  5. 500 — 1 × 256 + 15 × 16 + 4 = 256 + 240 + 4 = 500.

Flashcards

  1. 0xFF in decimal?
    Reveal answer255.
  2. Largest value of a k-bit field?
    Reveal answer2ᵏ − 1.
  3. Bits for 0..5000?
    Reveal answer13 (5001 values ≤ 8192).
  4. 2³²?
    Reveal answer4,294,967,296.

Exam shortcuts

  • Binary ↔ hex: group bits in fours from the right; convert each group. — always (pad the leftmost group with zeros).
  • Bits needed for N values = smallest k with 2ᵏ ≥ N. — counting values; remember 0..N is N + 1 values.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.