You are on page 1of 47

Module 1 - Number Systems

By
Prof. C. Prayline Rajabai

Assistant Professor
School of Electronics Engineering
VIT University

09-08-2019 DLD - Module 1 - Number Systems 1


Introduction
Real World Computer

Data Input device Data

Dear Mom: Keyboard 10110010…

Digital 10110010…
camera

09-08-2019 DLD - Module 1 - Number Systems 2


Common Number Systems

System Base Symbols


Decimal 10 0, 1, 2, 3, 4, 5,6, 7, 8, 9
Binary 2 0, 1
Octal 8 0, 1, 2, 3, 4, 5,6, 7
Hexadecimal 16 0, 1, 2, 3, 4, 5,6, 7, 8, 9, A, B, C, D, E, F

09-08-2019 DLD - Module 1 - Number Systems 3


Quantities/Counting
Dec Bin Oct Hex Dec Bin Oct Hex Dec Bin Oct Hex

0 0 0 0 8 1000 10 8 16 10000 20 10
1 1 1 1 9 1001 11 9 17 10001 21 11
2 10 2 2 10 1010 12 A 18 10010 22 12
3 11 3 3 11 1011 13 B 19 10011 23 13
4 100 4 4 12 1100 14 C 20 10100 24 14
5 101 5 5 13 1101 15 D 21 10101 25 15
6 110 6 6 14 1110 16 E 22 10110 26 16
7 111 7 7 15 1111 17 F 23 10111 27 17

09-08-2019 DLD - Module 1 - Number Systems 4


Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal

09-08-2019 DLD - Module 1 - Number Systems 5


Quick Example

2510 = 110012 = 318 = 1916

Base

09-08-2019 DLD - Module 1 - Number Systems 6


Decimal Numbers

Weight

12510 => 5 x 100= 5


1
2 x 10 = 20
1 x 102= 100
125

Base

09-08-2019 DLD - Module 1 - Number Systems 7


Decimal to Binary
• Technique 12510 = ?2

• Divide by two, keep track


of the remainder 2 125
62 1
• First remainder is bit 0 2
(LSB, least-significant bit) 2 31 0
• Second remainder is bit 1 2 15 1
7 1
• Etc. 2
2 3 1
1 1
2
0 1

12510 = 11111012

09-08-2019 DLD - Module 1 - Number Systems 8


Binary to Decimal
Bit “0”
• Technique
• Multiply each bit by 2n,
where n is the “weight” of
the bit 1010112 => 1 x 20 = 1
1 x 21 = 2
• The weight is the position of
the bit, starting from 0 on 0 x 22 = 0
the right 1 x 23 = 8
• Add the results 0 x 24 = 0
1 x 25 = 32
4310

09-08-2019 DLD - Module 1 - Number Systems 9


Decimal to Octal
• Technique 123410 = ?8

• Divide by 8
• Keep track of the remainder 8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228

09-08-2019 DLD - Module 1 - Number Systems 10


Octal to Decimal
• Technique
• Multiply each bit by 8n, where n is 7248 => 4 x 80 = 4
2 x 81 = 16
the “weight” of the bit 7 x 82 = 448
• The weight is the position of the 46810
bit, starting from 0 on the right
• Add the results

09-08-2019 DLD - Module 1 - Number Systems 11


Decimal to Hexadecimal
• Technique 123410 = ?16

• Divide by 16
• Keep track of the 16 1234
remainder 77 2
16
16 4 13 = D
0 4

123410 = 4D216

09-08-2019 DLD - Module 1 - Number Systems 12


Hexadecimal to Decimal
• Technique
• Multiply each bit by 16n,
where n is the “weight” of the
ABC16 => C x 160 = 12 x 1 = 12
bit 1
B x 16 = 11 x 16 = 176
• The weight is the position of A x 162 = 10 x 256 = 2560
the bit, starting from 0 on the 274810
right
• Add the results

09-08-2019 DLD - Module 1 - Number Systems 13


Octal to Binary
• Technique 7058 = ?2

• Convert each octal digit to


a 3-bit equivalent binary 7 0 5
representation

111 000 101

7058 = 1110001012

09-08-2019 DLD - Module 1 - Number Systems 14


Binary to Octal
• Technique 10110101112 = ?8

• Group bits in threes,


1 011 010 111
starting on right
• Convert to octal digits

1 3 2 7

10110101112 = 13278

09-08-2019 DLD - Module 1 - Number Systems 15


Hexadecimal to Binary
• Technique 10AF16 = ?2

• Convert each hexadecimal


digit to a 4-bit equivalent 1 0 A F
binary representation

0001 0000 1010 1111

10AF16 = 00010000101011112

09-08-2019 DLD - Module 1 - Number Systems 16


Binary to Hexadecimal
• Technique 10101110112 = ?16

• Group bits in fours, starting on right


• Convert to hexadecimal digits 10 1011 1011

2 B B

10101110112 = 2BB16

09-08-2019 DLD - Module 1 - Number Systems 17


Octal to Hexadecimal
• Technique 10768 = ?16

• Use binary as an
intermediary 1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16

09-08-2019 DLD - Module 1 - Number Systems 18


Hexadecimal to Octal
1F0C16 = ?8
• Technique
• Use binary as an intermediary 1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148

09-08-2019 DLD - Module 1 - Number Systems 19


Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don’t use calculator!

09-08-2019 DLD - Module 1 - Number Systems 20


Answer

Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF

09-08-2019 DLD - Module 1 - Number Systems 21


Fractions
• Decimal to decimal (just for logic)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14

09-08-2019 DLD - Module 1 - Number Systems 22


Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875

09-08-2019 DLD - Module 1 - Number Systems 23


Fractions
• Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001...
etc.

09-08-2019 DLD - Module 1 - Number Systems 24


Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don’t use calculator!

09-08-2019 DLD - Module 1 - Number Systems 25


Answer

Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82

09-08-2019 DLD - Module 1 - Number Systems 26


Binary-Coded Decimal (BCD), Excess 3 Code
Digit Bit pattern Excess 3
• Four bits per digit 8421 Code
0 0000 0011
Note: the following Note: the following 1 0001 0100
bit patterns are not bit patterns are not
used for BCD: used for Excess 3: 2 0010 0101
1010 0000 3 0011 0110
1011 0001 4 0100 0111
1100 0010
1101 1101 5 0101 1000
1110 1110 6 0110 1001
1111 1111
7 0111 1010
8 1000 1011
9 1001 1100
09-08-2019 DLD - Module 1 - Number Systems 27
Example
• 709310 = ? (in BCD)
7 0 9 3

0111 0000 1001 0011

09-08-2019 DLD - Module 1 - Number Systems 28


Signed Integers
• Previous examples were for “unsigned integers” (positive values
only!)
• Must also have a mechanism to represent “signed integers” (positive
and negative values!)
• E.g., -510 = ?2
• Two common schemes: sign-magnitude and twos complement

09-08-2019 DLD - Module 1 - Number Systems 29


Sign-Magnitude
• Extra bit on left to represent sign
• 0 = positive value
• 1 = negative value
• E.g., 6-bit sign-magnitude representation of +5 and –5:

+5: 0 0 0 1 0 1 -5: 1 0 0 1 0 1

+ve 5 -ve 5

09-08-2019 DLD - Module 1 - Number Systems 30


Ranges (revisited)
Binary
Unsigned Sign-magnitude
No. of bits Min Max Min Max
1 0 1
2 0 3 -1 1
3 0 7 -3 3
4 0 15 -7 7
5 0 31 -15 15
6 0 63 -31 31
n n-1 n-1
In General, n bits 0 2 -1 -(2 - 1) 2 -1

09-08-2019 DLD - Module 1 - Number Systems 31


Complement of Numbers
• Complements are used in digital computers to simplify the subtraction operation.

Complement for base – r system

Radix Complement Diminished radix complement


r’s complement (r-1)’s complement

• For Binary numbers r = 2


• 1’s complement and 2’s complement
• For Decimal numbers r = 10
• 9’s complement and 10’s complement

09-08-2019 DLD - Module 1 - Number Systems 32


Diminished Radix Complement - (r-1)’s complement
• For a given number N containing n digits, (r-1)’s complement is defined as (rn-1) -N
• 1’scomplement of (101100)2
= (26-1) – (101100) 2
= (1000000 – 1) - (101100) 2 = (111111) 2 - (101100) 2
= (010011)2
• 9’s complement of (546700)10
= (106-1) – (546700) 10
= (1000000 – 1) - (546700) 10 = (999999) 10 - (546700) 10
= (453299)10

Note : 1’s complement of a binary number is formed by changing 1’s to 0’s and 0’s to 1’s
09-08-2019 DLD - Module 1 - Number Systems 33
Radix Complement - r’s complement
• For a given number N containing n digits, r’s complement is defined as rn-N for N ≠
0 and 0 for N = 0. rn-N = [(rn-1) – N + 1]
• Most common scheme of representing negative numbers.

• 2’s complement of (101100)2


= (010011)2 + 1
= (010100) 2

• 10’s complement of (546700)10


= (453299)10 + 1
= (453300)10

09-08-2019 DLD - Module 1 - Number Systems 34


Twos Complement Example
• Represent -5 in binary using 2’s complement notation
1. Decide on the number of bits 6 (for example)

2. Find the binary representation of the +ve value in 6 bits

000101

3. Flip all the bits (1’s complement) +5


111010

4. Add 1 (2’s complement)


111010
+ 1
111011 -5

09-08-2019 DLD - Module 1 - Number Systems 35


Sign Bit
• In 2’s complement notation, the MSB is the sign bit (as with sign-
magnitude notation)
• 0 = positive value
• 1 = negative value

+5: 0 0 0 1 0 1 -5: 1 1 1 0 1 1

+ve 5 -ve

09-08-2019 DLD - Module 1 - Number Systems 36


“Complementary” Notation
• Conversions between positive and negative numbers are easy
• For binary (base 2)…

2’s C

-ve
+ve

2’s C

09-08-2019 DLD - Module 1 - Number Systems 37


Example
+5 0 0 0 1 0 1

1 1 1 0 1 0
2’s C
+ 1

-5 1 1 1 0 1 1

0 0 0 1 0 0
2’s C
+ 1

+5 0 0 0 1 0 1

09-08-2019 DLD - Module 1 - Number Systems 38


Exercise – 2’s C conversions
• Represent -20 as an 8-bit binary number in 2’s complement notation?
• Answer:

• 1100011 is a 7-bit binary number in 2’s complement notation. What


is the decimal value?
• Answer:

09-08-2019 DLD - Module 1 - Number Systems 39


Answer

• Represent -20 as an 8-bit binary number in 2’s complement notation?


• Answer: 1101100

• 1100011 is a 7-bit binary number in 2’s complement notation. What


is the decimal value?
• Answer: -29

09-08-2019 DLD - Module 1 - Number Systems 40


Ranges
Binary
No. of bits Unsigned Sign-magnitude 2’s complement
Min Max Min Max Min Max
1 0 1
2 0 3 -1 1 -2 1
3 0 7 -3 3 -4 3
4 0 15 -7 7 -8 7
5 0 31 -15 15 -16 15
6 0 63 -31 31 -32 31

n n-1 n-1 n-1 n-1


n 0 2 -1 -(2 - 1) 2 -1 -2 2 -1
09-08-2019 DLD - Module 1 - Number Systems 41
What is -5 plus +5?
• Zero, of course, but let’s see
Sign-magnitude Twos-complement

-5: 10000101 -5: 11111011


+5: +00000101 +5: +00000101
10001010 00000000

09-08-2019 DLD - Module 1 - Number Systems 42


2’s Complement Subtraction
• Easy
• No special rules
• Just subtract, well … actually … just add!

A – B = A + (-B)

add 2’s complement of B

09-08-2019 DLD - Module 1 - Number Systems 43


What is 10 subtract 3 using 2’s complement?

10 – 3 = 10 + (-3) = 7

+3: 000011
001010
1s C: 111100
+1: 1 +111101
-3: 111101
000111

09-08-2019 DLD - Module 1 - Number Systems 44


Exercises – Complementary Notations

• What is the 3-digit 10’s complement of 247?


• Answer:

• What is the 3-digit 10’s complement of 17?


• Answer:

• 777 is a 10’s complement representation of what decimal value?


• Answer:

09-08-2019 DLD - Module 1 - Number Systems 45


Answer

• What is the 3-digit 10’s complement of 247?


• Answer: 753

• What is the 3-digit 10’s complement of 17?


• Answer: 983

• 777 is a 10’s complement representation of what decimal value?


• Answer: 223

09-08-2019 DLD - Module 1 - Number Systems 46


Thank you

09-08-2019 DLD - Module 1 - Number Systems 47

You might also like