0% found this document useful (0 votes)
2 views

Number System

The document outlines various number systems including decimal, binary, hexadecimal, and octal, along with their respective values and conversion methods. It covers basic arithmetic operations such as addition, subtraction, multiplication, and division in these systems, as well as techniques for using complements. Additionally, it provides examples and methods for converting between different number systems and performing calculations.

Uploaded by

pramitha rm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Number System

The document outlines various number systems including decimal, binary, hexadecimal, and octal, along with their respective values and conversion methods. It covers basic arithmetic operations such as addition, subtraction, multiplication, and division in these systems, as well as techniques for using complements. Additionally, it provides examples and methods for converting between different number systems and performing calculations.

Uploaded by

pramitha rm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Number System Outline

n Number Systems
n Decimal
n Binary
n Hexadecimal
n Octal
n Addition
n Subtraction
n 2’s Complement
n Multiplication
n Division
Number System
n A system to express numbers
n Decimal: Base 10:
n 0,1,2,3,4,5,6,7,8,9
n Binary: Base 2:
n 0,1
n Hexadecimal: Base 16:
n 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
n Octal: Base 8:
n 0,1,2,3,4,5,6,7

Number Systems
Motivation
n Where might you encounter number systems in
other courses:
n EECS 2031

EECS 2031/2032
EECS 3214: Networks

EECS 3214 Computer Protocols


EECS 4411 DBMS
Disk recovery using checksums Hash Indexing for DB records

EECS 4411 DBMS


EECS4415 Hashing

EECS 4415 Big Data Systems


EECS 4415 Similarity

EECS 4415 Big Data Systems


Value of a number
To get the value of a number in any number system:
N digits number:
n Xn Xn-1…..X0 = (Xn * Basen) + (Xn-1 * Basen-1) + ….. + (X0* Base0)

n 4 digits Decimal number (Base 10):


n (X3 * 103) + (X2 * 102) + (X1 * 101) + (X0* 100)
n 3 digits Binary number (Base 2):
n (X2 * 22) + (X1 * 21) + (X0* 20)
n 3 digits Hexadecimal number (Base 16):
n (X2 * 162) + (X1 * 161) + (X0* 160)
n Table:
Basen Basen-1 ….. Base1 Base0
Xn Xn-1 ….. X1 X0

Number System
Decimal:
n Base 10
n Value of 5318:
n Xn Xn-1…..X0 = (Xn * Basen) + (Xn-1 * Basen-1) + ….. + (X0* Base0)

5318 = (5 * 103) + (3 * 102) + (1 * 101) + (8 * 100)


5318 = (5 * 1000) + (3 * 100) + (1 * 10) + (8 * 1)
5318 = (5000) + (300) + (10) + (8)

1000 100 10 1

5 3 1 8

Number Systems: Decimal


Binary
n Base 2
n Value of 11010:
n Xn Xn-1…..X0 = (Xn * Basen) + (Xn-1 * Basen-1) + ….. + (X0* Base0)

n 110102 = (1 * 24) + (1 * 23) + (0 * 22) + (1 * 21) + (0 * 20)


n 110102 = (1 * 16) + (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1)
n 110102 = (16) + (8) + (0) + (2) + (0)
n 110102 = 2610

16 8 4 2 1

1 1 0 1 0

Number System: Binary


Decimal To Binary
n Use the table: (Columns increases by a factor of 2 (Binary)
N …. 16 8 4 2 1

n Move from left to right, Put 1 if the column number fits into the
decimal number. Put 0 if it does not
n Then subtract the decimal number from the column number. Repeat
for the new number until reaching 1

Decimal To Binary Conversion


Decimal To Binary
n Convert 84:
64 32 16 8 4 2 1
1

n 84 – 64 = 20 remans to allocate
64 32 16 8 4 2 1
1 0 1

n 20 – 16 = 4 remans to allocate
64 32 16 8 4 2 1
1 0 1

n 4 – 4 = 0 Done
64 32 16 8 4 2 1
1 0 1 0 1 0 0
Decimal To Binary Conversion
Hexadecimal
n Base 16
n Value of ABC3
n Xn Xn-1…..X0 = (Xn * Basen) + (Xn-1 * Basen-1) + ….. + (X0* Base0)

n ABC316 = (A * 163) + (B * 162) + (C * 161) + (3 * 160)


n ABC316 = (A * 4096) + (B * 256) + (C * 16) + (3 * 1)
n ABC316 = (10 * 4096) + (11 * 256) + (12 * 16) + (3 * 1)
n ABC316 = (40960) + (2816) + (192) + (3)
n ABC316 = 4397110
4096 256 16 1

A B C 3

Number System: Hex


Decimal To Hexadecimal
n Convert 7401: 4096 fits into 7401 One Time
4096 256 16 1
1

n 7401 – 4096 = 3305 Remains. 256 fits into 3305 Twelve Times:
4096 256 16 1
1 C
n 3305 – (12 * 256) = 233 Remains. 16 fits into 233 Fourteen Time

4096 256 16 1
1 C E

n 233 – (14 * 16) = 9 Remains 1 fits into 9 Nine Time


4096 256 16 1
1 C E 9

Decimal To Hex Conversion


Addition Carry out
Add 45 + 78
1
4 5
2 8 +

3 (Need to carry out the 1)


Carry out when the sum of a column gives
us a two-digit number

Decimal Addition
Binary Addition

n Case 1: Case 2: Case 3: Case 4


0 0 1 1
0 + 1 + 0 1
----- ----- ----- -----
0 1 1 10 (Carry)

Binary Addition
Binary Addition
• Add: 11010 + 11100

1 1
1 1 0 1 0
1 1 1 0 0 +

1 1 0 1 1 0

Binary Addition
Hex Addition
n Add: AB4 + DE6
1 1
A B 4
D E 6 +

1 8 9 A

• B + E = 19 in hex we need to carry the 1


• 1 + A + D = 18 in hex, we carry the 1

Hex Addition
Subtraction
n Subtract: 64 -16
5 14
6 4
1 6 -

4 8

Decimal Subtraction
Binary Subtraction

n Case 1: Case 2: Case 3: Case 4


0 1 1 0
0 - 1 - 0 - 1
----- ----- ----- -----
0 0 1 ?

Binary Subtraction Cases


Binary Subtraction
• Subtract: 11010 - 1100
10
0 0 10
1 1 0 1 0
1 1 0 0 -

0 1 1 1 0

Binary Subtraction
Binary Subtraction
• Subtract: 1001 - 110
1
0 10 10
1 0 0 1
1 1 0 -

0 0 1 1

Binary Subtraction
Complements (Decimal)
n 9s Complement: Subtract 9 by each digit
n 15:
9 9
1 5 -

8 4
10s Complement = 9s Complement + 1
15: 84 + 1 = 85

10s Complement
Complements (Binary)
n 1s Complement: Subtract 1 by each digit
n 10110: 1 1 1 1 1
1 0 1 1 0 -

0 1 0 0 1
n 2s Complement = 1s Complement + 1
0 1 0 0 1
0 0 0 0 1 +

1 0 1 0 1 0
Negative sign Bit
Subtracting With Complement
n X1 - X2: (Decimal)
n Get 10s Complement of X2
n 10s Complement = 9s Complement + 1
n Add X1 and 10s Complement of X2
n If the sum has a carry out:
n Sum is a positive number à Discard the carry
n If the sum has no carry out:
n Sum is a negative number à Get 10s
Complement of the sum
Subtracting with Complements
Subtraction Using Complement
n Subtract: 64 -16:
n 1) 9s Complement of 16:
n 99 – 16 = 83
n 2) 10s Complement of 16:
n 83 + 1 = 84
n 3) 64 + 84:
1 6 4
8 4

4 8
Subtraction Using Complement
n Subtract: 16 - 64:
n 1) 9s Complement of 64:
n 99 – 64 = 35
n 2) 10s Complement of 64:
n 35 + 1 = 36
n 3) 16 + 36: 1 6
3 6 +
10s Complement
(No Carry) 5 2 à 48
n Ans: - 48 (Add minus sign because the number is
negative
Subtracting With Complement
n X1 - X2: (Binary)
n Get 2s Complement of X2
n 2s Complement = 1s Complement + 1
n Add X1 and 2s Complement of X2
n If the sum has a carry out:
n Sum is a positive number à Discard the carry
n If the sum has no carry out:
n Sum is a negative number à Get 2s
Complement of the sum
Subtracting with Complements
Subtracting With Complement
n Subtract: 11010 – 1100 (26-12)
n 1) 1s Complement of 1100
n 0011 (Invert all the bits : 0 -> 1, 1 -> 0)
n We need to add a 1 in the MSB (Negative bit): 10011
n 2) 2s Complement of 1100
n 10011 + 1 = 10100
n 3) Add 11010 + 10100 (Discard the carry)
1 1 0 1 0
1 0 1 0 0

1 0 1 1 1 0 = +14
Subtracting with Complements
Subtracting With Complement
n Subtract: 1100 – 11010 (12 - 26)
n 1) 1s Complement of 11010
n 00101 (Invert all the bits : 0 -> 1, 1 -> 0)
n We need to add a 1 in the MSB: 00101 -> 100101
n 2) 2s Complement of 11010 = 100101 + 1 = 100110
n 3) Add 001100 + 100110
0 0 1 1 0 0
1 0 0 1 1 0 +

1 1 0 0 1 0
No Carry: Negative number, we take 2s Complement and add negative
sign à 001110 Ans: -1110 = -14
Multiplication in Decimal
n Multiply: 23 * 15
1
2 3
1 5 x

1 1 5
2 3 0 +

3 4 5
Decimal Multiplication
Multiplication in Binary
n Multiply: 11001 x 101 (25 x 5)
1 1 0 0 1
1 0 1 x

1 1 0 0 1
0 0 0 0 0 0
1 1 0 0 1 0 0

1 1 1 1 1 0 1 = 125
Binary Multiplication
Division in Binary
n Divide: 110101/101 (53 / 5)
1 010
101 110101
101
00110
101
001 1
Division in Binary
n Divide: 101101/110 (45 / 6)
0111
110 101101
110
1010
110
100 1
110
011

You might also like