Skip to content

Syllabus · CS Computer Science and Information Technology

All topics in this subject
C programming foundations6
Arrays and pointers7
Recursion6
Linked lists, stacks and queues3
Trees, BSTs and heaps3
Graph foundations3
Algorithms foundations3
Discrete mathematics foundations15
Digital logic foundations22
Computer organization foundations3
Operating systems foundations3

Binary, hexadecimal and unsigned representation

Lesson 47 of 7410 minFree

Read the contract before reading the bits

A bit is one binary digit, either 0 or 1. A bit pattern is a sequence of bits. A numerical representation assigns a value to that sequence. The same pattern can mean different things under different representations, so always state the base, width and interpretation first. In this lesson, every stored value is an unsigned integer: there is no sign bit and every position contributes a nonnegative amount. We use mathematical integers for intermediate calculations, not a particular programming language's integer types.

Prerequisites: whole-number arithmetic, powers and quotient/remainder division. By the end, you should be able to convert small unsigned values between decimal, binary and hexadecimal, justify a width, and distinguish exact addition from retaining only the low bits. Signed encodings, fractions and floating point are outside this introductory lesson.

The contract for an n-bit unsigned representation is: n is a positive integer; there are exactly n positions; each bit b_i is 0 or 1; position i counts from 0 at the right; the value is the sum of b_i × 2^i for i from 0 to n−1. The rightmost bit is the least significant bit (LSB). The leftmost is the most significant bit (MSB). In unsigned interpretation the MSB has weight 2^(n−1); it is not a negative sign.

Place value and range

In base r, each digit is an integer from 0 through r−1, and moving one position left multiplies its weight by r. Thus decimal 305 means 3×100 + 0×10 + 5; binary 10110 means 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 22. Subscripts such as (10110)₂ or prefixes explained in context distinguish bases. An unlabelled 10 is ambiguous in a conversion problem.

For n bits there are 2^n distinct patterns: two independent choices at each position. The smallest unsigned value is 0. The largest is 1+2+...+2^(n−1)=2^n−1. There are 2^n values, but the largest value is one less because counting begins at zero. Four bits give 16 patterns and maximum 15, not 16. Eight bits give 256 patterns and range 0 through 255 inclusive.

A positive integer x needs the smallest n with x < 2^n. Equivalently n = floor(log₂ x)+1 for x≥1. Handle zero separately: its ordinary binary numeral is 0 and one bit suffices; this lesson does not use zero-width storage. To store every integer from 0 through M, choose positive n with M≤2^n−1. Avoid approximate logarithms near powers of two; comparing powers exactly is safer.

Worked example 1: decimal to binary

Convert 45 by repeated division by 2. Each remainder becomes the next bit from right to left:

Current quotientDivide by 2: next quotientRemainder
45221
22110
1151
521
210
101

Read the remainders from bottom to top: (101101)₂. Check independently by place value: 32+8+4+1=45. Six bits suffice because 32≤45<64. In an 8-bit field the same value is 00101101. Adding leading zeros changes width, not unsigned value. Adding a zero on the right instead multiplies the value by 2, provided the complete result is retained.

Why does the division method work? At each step x=2q+r with r∈{0,1}. The remainder is the coefficient of 2^0. Expanding q in the same way produces the higher coefficients. Stopping at quotient zero prevents unnecessary leading zeros. Reading top to bottom reverses significance and is a frequent mistake.

Hexadecimal is compact binary notation

Hexadecimal has base 16 and digit symbols 0–9, A, B, C, D, E, F for values 0–15. Uppercase and lowercase letters denote the same digit values. Since 16=2^4, exactly four binary positions correspond to one hex digit. A group of four bits is often called a nibble. Do not treat A as the decimal number 1 or as a variable in a hex numeral.

Decimal / दशमलवHexFour bits / चार bits
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
10A1010
11B1011
12C1100
13D1101
14E1110
15F1111

Worked example 2: group from the right

Convert (110101101)₂ to hexadecimal. Group from the LSB end into 1 | 1010 | 1101. Pad only the left group: 0001 | 1010 | 1101. The digits are 1, A, D, so the answer is (1AD)₁₆. Check: 1×256+10×16+13=429. The binary weights 256+128+32+8+4+1 also sum to 429. Padding on the right would multiply the number and give a different result.

In reverse, (2F)₁₆ becomes 0010 | 1111, or (00101111)₂ at width eight. Its decimal value is 2×16+15=47. If width is unspecified, 101111 is the same unsigned value. If width is explicitly eight, preserve the two leading zeros. Hex notation does not itself imply signedness or a fixed word size.

Worked example 3: width and overflow

Suppose a device stores counts 0 through 300 inclusive. Eight bits stop at 255, whereas nine bits stop at 511, so nine bits are necessary and sufficient. There are 301 possible counts; do not mistake “300 is the maximum” for “300 possible values.”

Now add two 4-bit unsigned values 1101 and 0110. They represent 13 and 6, so the exact sum is 19 = (10011)₂. That exact result needs five bits. If the specified operation keeps only four low bits, the stored result is 0011 = 3 and carry-out is 1. The mathematical sum is still 19. Truncation is not an assertion that 13+6=3 in ordinary integer arithmetic.

For two n-bit inputs a and b, with an optional incoming bit c∈{0,1}, define t=a+b+c. Then low=t mod 2^n and carry=floor(t/2^n). Since t≤2^(n+1)−1, carry is a bit. The reconstruction identity is t=carry×2^n+low. Unsigned overflow occurs exactly when carry=1, or t≥2^n. This test is for this addition contract; do not apply it blindly to signed arithmetic or arbitrary operations.

A dependable solving routine

  1. Write base, unsigned interpretation and required width.
  2. Expand place values or use repeated division; do not mix digit symbols with digit values.
  3. For binary/hex conversion, group into fours from the right and pad on the left.
  4. Check the result by converting back using a different method.
  5. For arithmetic, compute the exact integer first. Then report low bits and carry separately if the width requires them.

Common errors and quick reference

  • “n bits have maximum 2^n” confuses the count of patterns with the maximum value.
  • “A leading 1 means negative” violates the unsigned contract.
  • Dropping leading zeros is fine for an unrestricted numeral but wrong when an exact field width is requested.
  • Grouping hex chunks from the left without first aligning the right end changes digit boundaries.
  • A final carry is not one of the n retained bits; it has weight 2^n.

Reference: unsigned value = Σb_i2^i; range = 0…2^n−1; patterns = 2^n; one hex digit = four bits; exact sum = carry×2^n + low. These are representation facts, not claims about an entire machine's storage layout or byte order.

Original practice: six single-correct MCQs

These are original foundation questions, not previous-year questions. Choose exactly one option for each.

C01. What is the decimal value of the unsigned binary numeral (101101)₂?

A. 43 B. 44 C. 45 D. 46

Answer: C

A is incorrect: 43 has binary 101011; the weights of the middle low bits differ.

B is incorrect: 44=32+8+4 omits the final 1.

C is correct: 32+8+4+1=45.

D is incorrect: 46=32+8+4+2 would end in 10, not 01.

C02. Which pair gives the number of patterns and maximum value for a 7-bit unsigned field?

A. 128 and 127 B. 127 and 128 C. 128 and 128 D. 64 and 63

Answer: A

A is correct: 2^7=128 patterns encode values 0 through 127.

B is incorrect: it exchanges count and maximum, and 128 cannot fit.

C is incorrect: the maximum is 2^7−1, not 2^7.

D is incorrect: 64 patterns and maximum 63 describe six bits.

C03. How many bits are minimally needed to store every unsigned integer from 0 through 256 inclusive?

A. 7 B. 8 C. 10 D. 9

Answer: D

A is incorrect: seven bits stop at 127.

B is incorrect: eight bits stop at 255, so 256 is excluded.

C is incorrect: ten bits suffice but are not minimal; nine already work.

D is correct: nine bits cover 0 through 511, including all 257 required values.

C04. Which 8-bit binary pattern represents hexadecimal (B6)₁₆ as unsigned?

A. 10100110 B. 10110110 C. 11010110 D. 10110101

Answer: B

A is incorrect: 1010 is A, so this is A6.

B is correct: B=11=1011 and 6=0110; concatenate to obtain 10110110.

C is incorrect: 1101 is D, so this is D6.

D is incorrect: its last nibble is 0101=5, giving B5.

C05. Add unsigned 1110 and 0101 in a 4-bit adder with incoming carry 0. Which gives (low four bits, carry-out)?

A. 0011, 1 B. 10011, 0 C. 0011, 0 D. 1111, 1

Answer: A

A is correct: 14+5=19=1×16+3, giving low 0011 and carry 1.

B is incorrect: 10011 is the exact five-bit result, not four low bits.

C is incorrect: low 0011 is right, but a sum of 19 exceeds 15 so carry is 1.

D is incorrect: low 1111 is 15; combined with carry 1 it would reconstruct 31.

C06. Which hexadecimal numeral equals unsigned binary (1010111)₂?

A. A7 B. AE C. 57 D. 507

Answer: C

A is incorrect: A7 expands to 10100111, a different bit sequence.

B is incorrect: AE comes from padding the original on the right, doubling 87 to 174.

C is correct: pad left to 0101 0111; these groups are 5 and 7, giving decimal 87.

D is incorrect: inserting a middle zero hex digit changes place values; 507 is 1287.

Syllabus alignment and scope

This is an introductory lesson within Digital Logic, not complete GATE CS Digital Logic coverage. The official GATE 2027 CS syllabus includes Boolean algebra and minimization, combinational and sequential design, and number representation and arithmetic. Karnaugh maps, tabular minimization, sequential design, signed-number arithmetic and floating-point arithmetic require further lessons. The syllabus verifies relevance; examples and questions here are original.

Official GATE 2027 CS syllabus, Section 2 (checked 2026-10-14).

Technical convention reference; original worked examples and practice: MIT Computation Structures binary encoding.

Sign in to keep your progress. Sign in