Module-1: Number Systems
Dr. M. Rambabu
GITAM, Visakhapatnam
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 1/42
What is a Number System?
Why Do We Need Number Systems?
To represent quantities (students,
marks, money, etc.)
Real-Life Examples
To store and process information in
computers Everyday numbers
Decimal (Base-10)
To express data in different forms
(binary, decimal, hexadecimal) Computer data Binary
(Base-2)
Key Idea Colors in web design
Hexadecimal (Base-16)
A number system consists of:
A set of digits
A base (or radix)
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 2/42
Positional Representation: The Core Idea
Meaning of ”Positional”
The value of a digit depends on:
1 The digit itself
Quick Example (Base-10)
2 Its position (place value)
This is true for all number systems. 7392 = 7×103 +3×102 +9×101
+2 × 100
General Form 7 thousands place
3 hundreds place
(an an−1 . . . a1 a0 .a−1 a−2 . . . a−m )r 9 tens place
2 units place
Each digit contributes:
ai × r i
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 3/42
Why Are Positional Systems Useful?
Advantages
Easy for arithmetic (add,
subtract, multiply)
Compact representation of large Digit Ranges in Different Bases
numbers
Base-2 (Binary): 0, 1
Works for any base: 2, 8, 10, 16
... Base-8 (Octal): 0–7
Computer hardware follows Base-10 (Decimal): 0–9
positional logic Base-16 (Hex): 0–9, A–F
Digit Range
0 ≤ ai ≤ r − 1
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 4/42
Visualizing Positional Values
Digit Place Value Weight Contribution
7 Thousands 103 7000
3 Hundreds 102 300
9 Tens 101 90
2 Units 100 2
7392 = 7000 + 300 + 90 + 2
Takeaway
A number is simply a weighted sum of its digits.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 5/42
Expanded Positional Representation (Decimal Example)
General Representation
A number with a decimal point can be written as a sum of:
Positive powers of 10 (left of decimal)
Negative powers of 10 (right of decimal)
N = 10n an + 10n−1 an−1 + · · · + 101 a1 + 100 a0 + 10−1 a−1 + 10−2 a−2 + . . .
Example
For the decimal number:
(a3 a2 a1 a0 .a−1 a−2 a−3 )10
The expansion is:
103 a3 + 102 a2 + 101 a1 + 100 a0 + 10−1 a−1 + 10−2 a−2 + 10−3 a−3
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 6/42
Binary Number in Positional Form
Binary Digits
Binary uses only:
ai ∈ {0, 1}
Each digit is multiplied by a power of 2.
X
N= ai 2i
Example
Binary number: 11010.112
Expanded: 1 · 24 + 1 · 23 + 0 · 22 + 1 · 21 + 0 · 20
Fractional part: 1 · 2−1 + 1 · 2−2
Final result = 26.75
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 7/42
General Base-r Representation
Base-r Digits
Digits range from:
Example (Base-5)
0 ≤ ai ≤ r − 1
General expansion: (4021.2)5 = 4·53 +0·52 +2·51 +1·50
(an . . . a1 a0 .a−1 a−2 . . . a−m )r
= (511.4)10
= an r n +· · ·+a0 r 0 +a−1 r −1 +· · ·+a−m r −m
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 8/42
Examples: Octal and Hexadecimal Expansion
Octal (Base-8) Hexadecimal (Base-16)
Digits allowed: 0–7 Digits include: A=10 . . . F=15
(127.4)8 (B65F )16
= 1 · 82 + 2 · 81 + 7 · 80 + 4 · 8−1 = 11 · 163 + 6 · 162 + 5 · 161 + 15 · 160
= (87.5)10 = (46687)10
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 9/42
Fast Binary to Decimal Conversion
Only Add Bits That Are 1
(110101)2 = 32 + 16 + 4 + 1 = (53)10
Tip for Students
Each 1-bit contributes a power of 2. Ignore all positions where the digit is
0.
Useful Table
210 = 1024 1K
220 = 1, 048, 576 1M
230 = 1, 073, 741, 824 1G
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 10/42
Mathematical Representation of Numbers
General Formula
n
X
N= ai r i
i=−m
r base (2, 8, 10, 16) Used For
a digits
Conversions
i power of the base
i
Arithmetic
Binary representation in computers
Example (Binary)
11010.112 = 1 · 24 + 1 · 23 + 0 · 22 + 1 · 21 + 0 · 20 + 1 · 2−1 + 1 · 2−2
= 26.75
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 11/42
Decimal integer to base-r (division method)
Procedure
To convert a decimal integer N to base-r :
1 Divide N by r ; record the remainder R0 .
2 Replace N by the integer quotient and repeat until the quotient is 0.
3 The base-r digits are the remainders read from last to first (most
significant last).
Key point Notation
Remainders collected during successive If remainders are
divisions form the digits (LSB first). r0 , r1 , . . . , rk , number =
(rk rk−1 . . . r1 r0 )r .
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 12/42
Example: Convert (41)10 to binary
Division table
Dividend ÷2 Remainder
41 = 20, rem 1 r0 = 1
20 = 10, rem 0 r1 = 0
10 = 5, rem 0 r2 = 0
5 = 2, rem 1 r3 = 1
2 = 1, rem 0 r4 = 0
1 = 0, rem 1 r5 = 1
Result
Read remainders from bottom to top: (41)10 = (101001)2 .
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 13/42
Decimal fraction to base-r (multiplication method)
Procedure
To convert a fractional decimal 0.f to base-r :
1 Multiply the fraction by r .
2 Record the integer part as the next digit.
3 Replace the fraction by the new fractional part and repeat until
fraction becomes 0 or desired precision reached.
4 Digits appear in order: first integer part is the digit nearest the radix
point.
Tip
If fraction does not terminate, report repeating pattern or round to
required precision.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 14/42
Example: Convert (0.6875)10 to binary
Multiplication steps
Step Multiply Integer part (digit)
1 0.6875 × 2 = 1.375 1
2 0.375 × 2 = 0.75 0
3 0.75 × 2 = 1.5 1
4 0.5 × 2 = 1.0 1
Result
Collect digits after radix: 0.687510 = 0.10112 (terminates after 4 steps).
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 15/42
Example: Convert (153)10 to octal (base 8)
Division by 8
153 = 19, rem 1
19 = 2, rem 3
2 = 0, rem 2
Result
Read remainders bottom-up: (153)10 = (231)8 .
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 16/42
Example: Convert (0.513)10 to octal (illustration)
Multiplication by 8 (steps)
0.513 × 8 = 4.104 digit: 4
0.104 × 8 = 0.832 digit: 0
0.832 × 8 = 6.656 digit: 6
0.656 × 8 = 5.248 digit: 5
0.248 × 8 = 1.984 digit: 1
0.984 × 8 = 7.872 digit: 7
Result (to 7 significant figures)
(0.513)10 ≈ (0.406517 . . . )8 (digits shown from first multiplication
onward).
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 17/42
Combining integer and fraction conversions
Method
Convert integer and fractional parts separately, then join with radix point.
Another
Example
(153.513)10 ≈ (231.406517)8
From previous examples:
(combine integer (231)8 and
(41.6875)10 = (101001.1011)2 .
fractional approximation).
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 18/42
Octal − > Hexadecimal relations with Binary
Why octal and hex are convenient
Since 23 = 8 and 24 = 16:
One octal digit = 3 binary bits.
One hexadecimal digit = 4 binary bits.
Grouping binary digits simplifies conversion to/from octal/hex.
Binary to Octal Binary to Hex
Group binary digits in threes from Group binary digits in fours from
the radix point left and right. the radix point left and right.
Replace each group with the octal Replace each group with the
digit. hexadecimal digit.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 19/42
Table: Decimal, Binary, Octal, Hexadecimal (0–15)
Decimal Binary Octal Hex
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 Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 20/42
Grouping examples (binary ↔ octal/hex)
Binary to Octal example
Take binary: 10 110 001 101 011 111 100 000 1102 .
Group in 3 bits (pad left):
010 110 001 101 011 111 100 000 1102 → (261537406)8 .
Binary to Hex example
Group in 4 bits: 1011 1100 0110 11112 → (BC6F)16 .
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 21/42
Practical tips & pitfalls
Always align groups from the radix point outward (pad with leading
or trailing zeros if needed).
Fractions may not terminate in target base — detect repeating
patterns and indicate precision.
Use lookup table for hex digit conversions to avoid mistakes (A=10,
B=11, ... F=15).
When in doubt, verify by converting back to decimal.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 22/42
Exercises
1 Convert (95)10 to binary and octal.
2 Convert (0.3125)10 to binary and state whether it terminates.
3 Convert (1110101.1011)2 to hexadecimal.
4 Convert (0.2)10 to binary (show at least 8 fractional digits).
5 Convert the following binary number to octal using the grouping
method:
1101011110012 =?8
6 Convert the following binary number to hexadecimal using the
grouping method:
10111010011011112 =?16
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 23/42
Why Complements?
Purpose
Simplify subtraction operations in digital computers
Enable efficient logical manipulation
Result in simpler and cheaper hardware circuits
Types
For a base-r number system:
Radix complement (r ’s complement)
Diminished radix complement ((r − 1)’s complement)
Examples: Binary 1’s & 2’s; Decimal 9’s & 10’s
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 24/42
Diminished Radix Complement ((r − 1)’s Complement)
Binary (1’s complement)
Invert all bits:
Definition
1↔0
(r n − 1) − N
Examples:
Decimal (9’s complement)
Formed by subtracting each digit 1011000 → 0100111
from 9.
0101101 → 1010010
999999 − 546700 = 453299
Octal/Hex
999999 − 012398 = 987601 Subtract from:
7 (octal), F (hex)
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 25/42
Radix Complement (r ’s Complement)
Definition
Examples
For N ̸= 0 : rn − N Decimal:
For N = 0 : 0 10’s complement of 2389 = 7610 +
1 = 7611
Relation Binary:
2’s complement of 101100 = 010011
r’s complement =
+ 1 = 010100
(r-1)’s complement + 1
Shortcut
Decimal: keep trailing zeros, subtract next digit from 10, others from
9
Binary: keep trailing zeros and first 1, flip remaining bits
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 26/42
Complements with Radix Point
Procedure
Temporarily remove radix point
Form complement
Restore radix point in the same position
Property
Complement of complement returns original number:
r n − (r n − N) = N
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 27/42
Subtraction Using Complements
Procedure Example (Decimal)
To compute M − N:
1 Add M to r ’s complement of 72532 − 03250
N 10’s comp of 03250 = 96750
If end carry appears discard
2
72532 + 96750 = 169282
result is positive
If no carry
take r ’s Discard carry
3
complement prefix minus
69282
sign
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 28/42
Binary Subtraction Using 2’s Complement
Example: X − Y
X = 1010100 Example: Y − X
Y = 1000011 2’s complement of X :
2’s complement of Y : 0101100
0111101 1000011 + 0101100 = 1101111
Sum: No carry negative:
1010100 + 0111101 = 10010001 2’s complement = 0010001
Discard carry: −0010001
0010001
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 29/42
Using (r–1)’s Complement
Important
Sum using (r − 1)’s complement is **one less** than actual difference.
End-Around Carry
If carry occurs:
Add 1 to the sum
Using 1’s Complement
X = 1010100 Negative Result
Y = 1000011
1’s complement of Y: 1000011 + 0101011 = 1101110
0111100 No carry negative:
1010100 + 0111100 = 10010000 1’s comp = 0010001
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 30/42
Binary Codes – Overview & Need
Why Binary Codes?
Digital systems operate using 0 and
1.
Any symbol can be represented
using binary patterns. Examples
An n-bit binary code represents
combinations.
2n 4 elements 2 bits: 00, 01,
10, 11
Stored bit patterns generally 8 elements 3 bits
16 elements 4 bits
represent coded data, not raw
numbers.
Minimum bits needed for N
symbols:
n = ⌈log2 N⌉
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 31/42
BCD Code – Introduction & Representation
Digit BCD (8421)
0 0000
Key Points 1 0001
Decimal digits (0–9) encoded using 2 0010
4 bits. 3 0011
4 0100
Only 10 of 16 possible 4-bit 5 0101
patterns used. 6 0110
A k-digit decimal number uses 4k 7 0111
bits. 8 1000
9 1001
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 32/42
Binary vs BCD & BCD Addition Rules
BCD Addition Rules
Add digits as binary.
Binary vs BCD Example
If sum ≥ 1010, it is invalid
Decimal: 185
for BCD.
BCD: 0001 1000 0101
Correction: add 0110
Binary: 10111001 (decimal 6).
Observation: BCD uses more bits but Correction needed if:
simplifies human-oriented I/O. 1 Sum ≥ 1010
2 A binary carry is
generated
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 33/42
Example: BCD Addition & Decimal Arithmetic
BCD Addition Example Signed Decimal in BCD
Sign-magnitude or 10’s
184 + 576 = 760
complement.
Steps: Sign digit (4 bits):
1 Add digitwise. + : 0000
2 Apply correction (add 6) when – : 1001
needed. 10’s complement = 9’s
3 Propagate carry to next digit. complement + 1.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 34/42
Other Decimal Codes & Gray Code
Decimal Codes Gray Code
Many 4-bit codes exist: Only one bit changes between
1 BCD (8421) consecutive values.
2 2421
(self-complementing) Prevents transition errors.
3 Excess-3 Used in:
(self-complementing) Encoders
4 8-4-(-2)-1 (mixed ADCs
weights) Mechanical sensors
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 35/42
ASCII Code & Summary
ASCII Code
Summary
Standard 7-bit code for 128
characters. Binary codes represent symbols
and data.
Includes letters, digits, symbols,
control characters. BCD simplifies decimal I/O.
Examples: Gray code reduces transition
errors.
A = 1000001
ASCII = standard alphanumeric
5 = 0110101
coding.
@ = 1000000
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 36/42
Signed vs Unsigned Binary Numbers
Unsigned Numbers
Signed Numbers
Represent only positive integers
(including 0). Leftmost bit = sign bit.
All bits interpreted as 0 → positive, 1 → negative.
magnitude. Example:
01001 → +9
Example: 110012 = 25
11001 → −9 (signed)
(unsigned).
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 37/42
Representing Negative Numbers
Three Signed Binary Systems
Decimal Sign-Magnitude 1’s Comp 2’s Comp
+9 00001001 00001001 00001001
−9 10001001 11110110 11110111
2’s complement eliminates 0 and avoids negative-zero issue.
Most computers use 2’s complement for signed arithmetic.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 38/42
Why 2’s Complement?
Advantages
One representation of zero.
Addition/subtraction performed like unsigned arithmetic.
No separate sign handling.
Negative numbers obtained easily via 2’s complement.
Recall
To find the 2’s complement:
Invert bits + 1
Example:
00001001 ⇒ 11110110 + 1 = 11110111
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 39/42
Subtraction Using 2’s Complement
Key Rule
A − B = A + (2’s complement of B)
Example: (−6) − (−13)
11111010 − 11110011
Convert the subtrahend to Convert −13:
2’s complement.
2′ s comp = 00001101
Add to minuend.
Discard final carry. Add:
11111010 + 00001101 = 1 00000111
Discard carry 00000111 = +7
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 40/42
Overflow Conditions
Signed Overflow
Unsigned Overflow Occurs when:
Occurs if a carry is produced out of Adding two positives gives
MSB. negative result.
Adding two negatives gives
1111 + 0001 → overflow positive result.
Overflow = Cin ⊕ Cout
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 41/42
Any Questions?
Let’s Discuss!
Your doubts help everyone learn better.
Number Systems Dept. of CSE, GITAM, Visakhapatnam Dr. M. Rambabu 42/42