0% found this document useful (0 votes)
1 views47 pages

Chapter 4

The document provides an overview of numbering systems used in digital design, including decimal, binary, hexadecimal, and octal systems. It explains the representation of numbers in these systems, the rules for zero-extension, and conversion methods between different bases. Additionally, it covers binary addition and multiplication, as well as the significance of hexadecimal for compact representation in computing.

Uploaded by

ot140018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views47 pages

Chapter 4

The document provides an overview of numbering systems used in digital design, including decimal, binary, hexadecimal, and octal systems. It explains the representation of numbers in these systems, the rules for zero-extension, and conversion methods between different bases. Additionally, it covers binary addition and multiplication, as well as the significance of hexadecimal for compact representation in computing.

Uploaded by

ot140018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

NUMBERING SYSTEM

LECTURE SET 05
CHAPTER 01 (DIGITAL DESIGN BOOK)

CRs NO:1502170
INTRODUCTION TO CYBER SECURITY

M5 - 220 [email protected] Dr. Saddaf Rubab


M5 - 221 [email protected] Dr. Khalid Javeed
DIGITAL COMPUTER SYSTEMS
Digital systems consider discrete amounts of data.
 Examples:
 26 letters in the alphabet
 10 decimal digits

 Larger quantities can be built from discrete values:


 Words made of letters
 Numbers made of decimal digits (e.g. 239875.32)

 Easy to represent binary values electrically


 Voltages and currents.
 Can be implemented using circuits
 Create the building blocks of modern computers 2
NUMBER SYSTEMS

 Decimal base or radix---> 10


 Binary base or radix---> 2
 Hexadecimal base or radix---> 16
 Octal base or radix---> 8

3
ZERO-EXTEND RULE FOR UNSIGNED
 In decimal numbering system
 70.0 = 070.0 = 0070.0 = 00070.0 …etc.
 0.9 = 0.90 = 0.900 = 0.9000 = 0.90000 …etc.

 Or
 Adding zeros to the left side of the integer part does not change its value
 Adding zeros to the right side of the fractional part does not change its
value
 Same rule for other number system
 E.g., in binary system
 11.0𝑏𝑏 = 011.0𝑏𝑏 = 0011.0𝑏𝑏 = 00011.0𝑏𝑏 … etc.
 11.01𝑏𝑏 = 11.01𝟎𝟎𝑏𝑏 = 11.01𝟎𝟎𝟎𝟎𝑏𝑏 = 11.01𝟎𝟎𝟎𝟎𝟎𝟎𝑏𝑏 … etc. 4

 11.01𝑏𝑏 = 011.01𝟎𝟎𝑏𝑏 = 0011.01𝟎𝟎𝟎𝟎𝑏𝑏 = 00011.01𝟎𝟎𝟎𝟎𝟎𝟎𝑏𝑏


DECIMAL
 Most people today use decimal representation to count. In the decimal
system there are 10 digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 Example 1: Consider the number 7234. It can be represented as
7*10³+ 2*10² + 3*10¹ + 4*10º
 Where:
 7 is in the thousand’s place
 2 is in the hundred’s place
 3 is in the ten’s place
 4 is in the one’s place.
5
 Important note: any number in power of zero is 1, even zero in power of
zero is 1.
DECIMAL

 Example 2: (Decimal Points)


 Consider the number 7234.567. It is represented as
7*10³+ 2*10² + 3*10¹ + 4*10º+ 5*10-1+ 6*10-2+ 7*10-3
 Where:
 5 is in the 1/10th place
 6 is in the 1/100th place
 7 is in the 1/1000th place

6
BINARY

 The bit is the smallest piece of information that can be stored


in a computer.
 It can have one of two values 0 or 1. Think of a bit as a
switch that can be either on or off.
 For example:
 Consider the binary number 1101. It can be represented as
1*2³+ 1*2² +0*2¹ + 1*2º
 In decimal:
8 + 4 + 0 + 1 = 13
7
BINARY

 Consider the binary number 1101.101. It can be represented


as:
1*2³+ 1*2² +0*2¹ + 1*2º +1*2-1 +0*2-2 +1*2-3
 The equivalent decimal number is
13 + 0.5 + 0 + 0.125 = 13.625
 To represent larger numbers, we have to group series of bits
 Nibble - A nibble is a group of four bits - (1101)2
 Byte - A byte is a group of eight bits - (11001001)2 8
BINARY ADDITION

 Binary addition is very simple.


 This is best shown in an example of adding two binary numbers…

9
BINARY MULTIPLICATION

 Binary multiplication is much the same as decimal multiplication,


except that the multiplication operations are much simpler…

10
THE GROWTH OF BINARY NUMBERS

11
TABLE OF CONVERSION BETWEEN DEC,
BIN, AND HEX
Decimal (Base 10) Binary (Base 2) Hexadecimal (base
16)
00 0000 0
01 0001 1
02 0010 2
03 0011 3
04 0100 4
05 0101 5
06 0110 6
07 0111 7
08 1000 8
09 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F 12
TABLE OF CONVERSION BETWEEN DEC,
BIN, AND OCT
Decimal Binary Octal (base 8)
(Base 10) (Base 2)
00 000 0
01 001 1
02 010 2
03 011 3
04 100 4
05 101 5
06 110 6
07 111 7

13
WHY HEXADECIMAL?

 Hexadecimal is meaningful to humans, and easy to work


with for a computer
 Compact
 A byte is composed of 8 bits
 One byte can thus be expressed by 2 digits in hexadecimal
 11101111𝑏𝑏 → EFℎ
 00010110𝑏𝑏 → 16ℎ
 Simple to convert them to binary

14
UNDERSTANDING HEXADECIMAL

 Hexadecimal numbers are made of 16 digits:


(0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F)
 How many items does a hex number represent?
(3A9F)16 = 3x163 + 10x162 + 9x161 + 15x160 = 15,00710
 What about fractions?
(2D3.5)16 = 2x162 + 13x161 + 3x160 + 5x16-1 = 723.312510
 Note that each hexadecimal digit can be represented with four bits.
(1110)2 = (E)16
 Groups of four bits are called a nibble.
(1110)2
15
PUTTING IT ALL TOGETHER
Decimal (Base Binary Octal (Base Hexadecimal
10) (Base 2) 8) (base 16)
00 0000 0 0
 Binary, octal, and 01 0001 1 1

hexadecimal similar 02
03
0010
0011
2
3
2
3

 Easy to build 04
05
0100
0101
4
5
4
5
circuits to operate 06 0110 6 6

on these 07 0111 7 7

representations
08 1000 8
09 1001 9

 Possible to convert
10 1010 A
11 1011 B
between the three 12 1100 C

formats 13
14
1101
1110
D
E
15 1111 F
CONVERSIONS
DECIMAL TO ANY BASE ‘N’
 Divide the decimal number by base ‘n’.
 For example,
 Decimal --> Binary, divide by 2 until we reach 0
 Convert (41)10 to binary
DECIMAL TO ANY BASE ‘N’

 Decimal to Octal, convert (153)10 to (??? )8


DECIMAL TO ANY BASE ‘N’

 Convert fraction from decimal to binary. (0.6875)10 to (???)2

1011
EXAMPLE
Question
 Convert fraction from decimal to binary. (97.231)10 to (???)2
Solution
CONVERTING FROM BINARY TO
HEXADECIMAL
Decimal (Base Binary Hexadecimal
10) (Base 2) (base 16)
 Starting from the point and working left and 00 0000 0
right, group each 4 bits and convert them to 01 0001 1

the matching hexadecimal digit 02 0010 2


03 0011 3
 If there isn’t enough bits, expand with 0’s 04 0100 4
05 0101 5
06 0110 6

 Convert (10110001101011.111100000110)2 07 0111 7


08 1000 8
to hex (???)16
09 1001 9

 (10110001101011.111100000110)2 10 1010 A
11 1011 B
 (0010110001101011.111100000110)2 12 1100 C
13 1101 D
 (2C6B.F06)h 14 1110 E
15 1111 F
CONVERTING FROM HEXADECIMAL TO
BINARY:
Decimal (Base Binary (Base Hexadecimal
10) 2) (base 16)

1. Directly convert each Hexadecimal digit to its binary 00 0000 0


01 0001 1
equivalent
02 0010 2
 Convert the following from Hex to Binary 03 0011 3
04 0100 4
(306.D)h 05 0101 5
06 0110 6
07 0111 7

0011 0000 0110 1101 08 1000 8


09 1001 9
10 1010 A
11 1011 B
12 1100 C
(F42.3)h
13 1101 D
14 1110 E
15 1111 F
1111 0100 0010 0011 23
CONVERTING FROM BINARY TO OCTAL
 Starting from the point and working left and right,
group each 3 bits and convert them to the matching Decimal Binary Octal (base
octal digit (Base 10) (Base 2) 8)
 If there isn’t enough bits, expand with 0’s 00 000 0
01 001 1
02 010 2
 Convert (10110001101011.111100000110)2 to octal 03 011 3
 (10110001101011.111100000110)2 04 100 4
 (010110001101011.111100000110)2 05 101 5
06 110 6
 (26153.7406)8
07 111 7

24
CONVERTING FROM OCTAL TO BINARY:

Decimal Binary Octal (base


1. Directly convert each Octal digit to its binary (Base 10) (Base 2) 8)
equivalent
00 000 0
 Convert the following from Octal to Binary 01 001 1
(326.7)8 02 010 2
03 011 3
011 010 110. 111
04 100 4
05 101 5
06 110 6
07 111 7
(307.5)8
011 000 111. 101

25
NUMBER RANGES
 Unsigned Numbers ranges in binary
 For n bits: 0 → 2n-1
 Examples
 2 Bit
 16 Bit
 0→3
 0 → 65,535
 00, 01, 10, 11
 32 Bit
 4 Bit
 0 → 4,294,967,295
 0 → 15
 64 Bit
 0000, 0001, 0010,
0011, 0100, 0101,  0 → 18,446,744,073,709,599,999
0110, 0111, 1000,
1001, 1010, 1011,
1100, 1101, 1110,
1111
 8 Bit

 0 → 255
UNKNOWN RADIX

Example

Lets say we need


to find radix b
UNKNOWN RADIX

Question
 Determine the base or radix of the numbers in the following relation
 25/5 = 7

Lets say we need


Solution to find radix b
BINARY ADDITION

 Addition table

+ 0 1
0 0 1
1 1 0
Carry
1

29
BINARY ADDITION

 Example
 Consider 110 + 810 using binary addition
0001
+ 1000
__________
1001

 Result: 10012 = 910


30
BINARY ADDITION

 Example
 Consider 1410 + 910 using binary addition
1
Carry 1110
+1001
1
10111

 Result: 101112 = 2310

31
BINARY ADDITION
 Example
 Consider 2110 + 810 using binary addition

10101
+ 01000
__________
11101

 Result: 111012 = 2910


32
BINARY ADDITION
 Example
 Consider 510 + 2710 using binary addition

1 1 1 1 1
00101
+ 11011
_________
_
100000

 Result: 1000002 = 3210


33
BINARY ADDITION
 Example
 Consider 710 + 3110 using binary addition

1 1 1 1 1
00111
+ 11111
_________
_
100110

 Result: 1001102 = 3810


34
SUBTRACTION IN COMPUTER SYSTEMS

 Implementing the traditional way of subtraction that we use as human


beings is expensive for the computers
 As we will see later, addition is very easy and fast to be accomplished
using the logic gates that are used by computers
 For instance,
 Instead of calculating 10 – 6 = 4
 We use 10 + (-6) = 4
 Hence, we need a way to represent the negative numbers
 That’s why we have the complement concept
35
COMPLEMENTS

 For any base-r system, there are two types of complements:


 The Radix Complement: r’s complement and
 The Diminished Radix Complement (r-1)’s complement

 For example, for the binary system (r=2):


 The Radix Complement is the 2’s Complement
 The Diminished Radix Complement is the 1’s Complement

36
RADIX COMPLEMENT

 Complements, in mathematics, is a technique used to subtract one number from


another using only addition of positive numbers
 This method was commonly used in mechanical calculators and is still used in
modern computers
 The complements for any decimal digit can be for:
 Nines' complement (9th complement)
 Tens’ complement (10th complement)

37
9TH AND 10TH COMPLEMENT
Digit 9th
 The 9th' complement of a decimal digit is: complement
0 9
 The number that must be added to it to
1 8
produce 9 2 7
 E.g., the 9th complement of 3 is 6. 3 6
4 5
 10th complement of a decimal digit is: 5 4

 The number that must be added to it to 6 3


7 2
produce 10
8 1
 E.g., the 10th complement of 3 is 7. 9 0

38
COMPLEMENT
 1’s Complement: Obtained by Subtracting each bit from 1.
 Example:
 1’s complement of 0011001 is
1111111
- 0011001
---------------  OR Simply flip each
1100110 bit
 1’s complement of 1000101 is  0 to 1
1111111  1 to 0
- 1000101
---------------
0111010
2’S COMPLEMENT OF BINARY SYSTEM
 2’s complement is 1’s complement +1
 Example:
 Find the 2’s complement of 1101111

The 1’s complement is 0010000


+ 1
-----------
The 2’s complement is 0010001

 Or another trick:
 Start from right to left (i.e., from least significant bit to most significant bit)
 If the bit is zero; keep it and move to the next bit
 If the bit is one; keep it and flip the remining bits and quit
 2’s complement of 1101111 is 0010001 40
2’S COMPLEMENT EXAMPLES

 Find the 2’s complement of (11101011)2

 Find the 2’s complement of (11101000)2

 Find the 2’s complement of (00101001)2

41
SUBTRACTION WITH COMPLEMENTS

42
SUBTRACTION WITH COMPLEMENTS
 M – N = (189)10 – (24)10 = (10111101)2 – (11000)2
1. Expand the second number to the same number of bits as the first by extending
to the left with 0’s
 (11000)2 becomes (00011000)2
2. Find the 2’s complement of the second number
 2’s complement of (00011000)2 is (11101000)2
3. Add the first number to the 2’s complement of the second number
10111101 (189)10
+ 11101000 + (-24)10
1 10100101 (165)10

4. Discard the end carry 43


SUBTRACTION WITH COMPLEMENTS
 M – N = (128)10 – (100)10 = (10000000)2 – (1100100)2
1. Expand the second number to the same number of bits as the first by extending
to the left with 0’s
 (1100100) becomes (01100100)
2. Find the 2’s complement of the second number
 2’s complement of (01100100)2 is (10011100)2
3. Add the first number to the 2’s complement of the second number
10000000 (128)10
+ 10011100 + (-100)10
1 00011100 (28)10

4. Discard the end carry


44
SUBTRACTION WITH COMPLEMENTS
 M – N = (24)10 – (189)10 = (11000)2 – (10111101)2
1. Expand the second number to the same number of bits as the first by extending
to the left with 0’s
 N.A.
2. Find the 2’s complement of the second number
 2’s complement of (10111101)2 is (01000011)2
3. Add the first number to the 2’s complement of the second number
00011000 (24)10
+ 01000011 + (-189)10
01011011 -(165)10

4. No carry => Result = –(2’s complement of (01011011)2) = -(10100101)2 = – 45


(165)10
SUBTRACTION WITH COMPLEMENTS
 M – N = (100)10 – (128)10 = (1100100)2 – (10000000)2
1. Expand the second number to the same number of bits as the first by extending
to the left with 0’s
 N.A.
2. Find the 2’s complement of the second number
 2’s complement of (10000000)2 is (10000000)2
3. Add the first number to the 2’s complement of the second number
01100100 (100)10
+ 10000000 + (-128)10
11100100 (-28)10

4. No carry => Result = –(2’s complement of (11100100)2) = -(00011100)2 = – 46


(28)10
REFERENCES

Chapter 1
Mano, M. M. (2017). Digital design: with an introduction to the
verilog. 6th Edition. Prentice Hall. ISBN 9780134549897.

47

You might also like