Download as pdf or txt
Download as pdf or txt
You are on page 1of 115

Computer Organization & Assembly

Language

BS Semester-III

Lecture-2:
Number Systems-I

Prof. Dr. Syed Asad Raza Kazmi


Chairperson

Department of Computer Science


GC University Lahore

JULY, 2022
Course Outlines: 2

Course Outlines:
Computer Arithmetic, Integer representation, integer arithmetic, floating-
point representation, floating-point arithmetic, Instruction Sets: Character-
istics and Functions Machine Instruction Characteristics, Types of Operands,
Pentium Data Types, Types of Operations, Instruction Sets: Addressing
Modes and Formats Addressing, Pentium Addressing Modes, Instruction
Formats, Pentium Instruction Formats, Introduction to Assembly Language
with debug, Structure of Assembly Language Programs and Flag Regis-
ter, Control Flow Instructions, Addressing Modes, Stack & Procedures, Bit
Manipulation Instructions, Macros, Interrupts, Multiplication and Division
Instructions.

2/70
Reference Books
Myths About Assembly Language 9

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

9/70
Myths About Assembly Language 10

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

9/70
Myths About Assembly Language 11

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

9/70
Myths About Assembly Language 12

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

9/70
Myths About Assembly Language 13

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

9/70
Myths About Assembly Language 14

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

9/70
Myths About Assembly Language 15

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

Improved compiler technology has eliminated the need for assembly


language.

9/70
Myths About Assembly Language 16

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

Improved compiler technology has eliminated the need for assembly


language.

Today, machines are so fast that we no longer need to use assembly.

9/70
Myths About Assembly Language 17

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

Improved compiler technology has eliminated the need for assembly


language.

Today, machines are so fast that we no longer need to use assembly.

If you need more speed, you should use a better algorithm rather than
switch to assembly language.

9/70
Myths About Assembly Language 18

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

Improved compiler technology has eliminated the need for assembly


language.

Today, machines are so fast that we no longer need to use assembly.

If you need more speed, you should use a better algorithm rather than
switch to assembly language.

Machines have so much memory today, saving space using assembly is not
important.

9/70
Myths About Assembly Language 19

Myths About Assembly Language

Assembly language has a pretty bad reputation


Assembly is hard to learn.

Assembly is hard to read and understand.

Assembly is hard to debug.

Assembly is hard to maintain.

Assembly is hard to write.

Assembly language programming is time consuming.

Improved compiler technology has eliminated the need for assembly


language.

Today, machines are so fast that we no longer need to use assembly.

If you need more speed, you should use a better algorithm rather than
switch to assembly language.

Machines have so much memory today, saving space using assembly is not
important.

Assembly language is not portable.

9/70
What’s Right With Assembly Language? 20

Assembly language has several benefits:

I Speed: Assembly language programs are generally the


fastest programs around.
What’s Right With Assembly Language? 21

Assembly language has several benefits:

I Speed: Assembly language programs are generally the


fastest programs around.
I Space: Assembly language programs are often the smallest.
What’s Right With Assembly Language? 22

Assembly language has several benefits:

I Speed: Assembly language programs are generally the


fastest programs around.
I Space: Assembly language programs are often the smallest.
I Capability: You can do things in assembly which are difficult
or impossible in HLLs.
What’s Right With Assembly Language? 23

Assembly language has several benefits:

I Speed: Assembly language programs are generally the


fastest programs around.
I Space: Assembly language programs are often the smallest.
I Capability: You can do things in assembly which are difficult
or impossible in HLLs.
I Knowledge: Your knowledge of assembly language will help
you write better programs, even when using HLLs.

10/70
Taken from CS429: Computer Organization and Architecture Introduction by Dr. Bill Young, thanks to him
Number Systems
Types of Number System

https://www.cuemath.com/numbers/number-systems/
Machine-Level Programming I 28

Machine-Level Programming

Binary Numbers - The Computer Number System

1 Number systems are simply ways to count things.

2 Ours is the base-10 or radix-10 system.

3 Note that there is no symbol for ”10” - or for the base of any
system.

4 We count 1,2,3,4,5,6,7,8,9, and then put a 0 in the first


column and add a new left column, starting at 1 again.

5 Then we count 1-9 in the first column again.

15/70
Machine-Level Programming II 29

Example

1 4 6 5 0 9 3
6 5 4 3 2 1
10 10 10 10 10 10 100

1,465,093 = 1 x one million + 4 x one hundred thousand + 6 x ten


thousand + 5 x one thousand + 0 x one hundred + 9 x ten + 3 x one.

16/70
Positional Notation -A History 30

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
Positional Notation -A History 31

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
• MCMXCVI = 1996, but MM = 2000!
(M = 1000, C = 100, X = 10, V = 5, I = 1)
Positional Notation -A History 32

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
• MCMXCVI = 1996, but MM = 2000!
(M = 1000, C = 100, X = 10, V = 5, I = 1)
• VII = 7 (5+1+1), but XC = 90 (100 - 10),
Positional Notation -A History 33

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
• MCMXCVI = 1996, but MM = 2000!
(M = 1000, C = 100, X = 10, V = 5, I = 1)
• VII = 7 (5+1+1), but XC = 90 (100 - 10),

• and (worst yet!) XLVII = 47 (50 - 10+5+1+1).


Positional Notation -A History 34

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
• MCMXCVI = 1996, but MM = 2000!
(M = 1000, C = 100, X = 10, V = 5, I = 1)
• VII = 7 (5+1+1), but XC = 90 (100 - 10),

• and (worst yet!) XLVII = 47 (50 - 10+5+1+1).

• Even worse: X . C = M, L/V=X. Ouch!


Positional Notation -A History 35

Positional Notation -A History

Heritage of western culture:


The (difficult) Roman representation of numbers:
• MCMXCVI = 1996, but MM = 2000!
(M = 1000, C = 100, X = 10, V = 5, I = 1)
• VII = 7 (5+1+1), but XC = 90 (100 - 10),

• and (worst yet!) XLVII = 47 (50 - 10+5+1+1).

• Even worse: X . C = M, L/V=X. Ouch!

A better idea – positional notation:

17/70
Positional Notation 36

Positional Notation

4621 6= 1264

Each digit in a column represents a multiplier of the power of


the base (10) represented by that column.

The first column on the right is the zeroth power of 10.


Succeeding columns to the left represent higher powers of
10.

196510 = 1 × 103 + 9 × 102 + 6 × 101 + 5 × 100

18/70
Positional Number Systems 37

Positional Number Systems

A good example of a positional number system is the


decimal which we use in our daily lives.

Another example is the binary which is used as the basic


number system for all computers.

In the positional number system, a number is represented by


a string of digits where the position of each digit is associated
with a weight.

In general, a positional number is expressed as:

dm−1 dm−2 · · · d1 d0 .d−1 d−2 · · · d−n

19/70
Positional Number Systems 38

Positional Number Systems

In general, a positional number is expressed as:

dm−1 dm−2 · · · d1 d0 .d−1 d−2 · · · d−n

• where dm−1 is referred to as the most significant digit


(MSD) and
• d−n as the least significant digit (LSD).

• Each digit position has the associated weight bi , where b is


called the base or radix.
• The point in the middle is referred to as a radix point and is
used to separate the fractional part of the number (which is
in the right side of the radix point) and the integer part
(which is in the left side of the radix point).

20/70
Positional Number Systems 39

Positional Number Systems

In general, a positional number is expressed as:

dm−1 dm−2 · · · d1 d0 .d−1 d−2 · · · d−n

• The fraction is the part of the magnitude of a number which


is less than unit (e.g. fraction < 1) and thus it is called a
fraction.
• The value D of a positional number is calculated using:

m−1
X
D= di · b i .
i=−n

21/70
Positional Number Systems: Example 40

Positional Number Systems: Example

EXAMPLE:
The value of 245.378

D = 2 · 82 + 4 · 81 + 5 · 80 + 3 · 8−1 + 7 · 8−2
= 165.48437510

22/70
Positional Number Systems: Example 41

Positional Number Systems: Example

EXAMPLE:
Decorate a 43-year-old’s birthday cake with only three candles.

Light all three candles and read them as a base-6 number, i.e.

43 = 62 + 61 + 60

23/70
The Computer
Number System
The Computer Number System 43

The Computer Number System

All computers use the binary system :


• Binary number system: Base = 2.
The Computer Number System 44

The Computer Number System

All computers use the binary system :


• Binary number system: Base = 2.

• Thus there are 2 numbers: 0 and 1.


The Computer Number System 45

The Computer Number System

All computers use the binary system :


• Binary number system: Base = 2.

• Thus there are 2 numbers: 0 and 1.

• A single binary number is called a Binary digIT, or bit.


Computers perform operations on

binary number groups called words

Today, most computers use 32- or 64- bit words:


The Computer Number System 46

The Computer Number System

All computers use the binary system :


• Binary number system: Base = 2.

• Thus there are 2 numbers: 0 and 1.

• A single binary number is called a Binary digIT, or bit.


Computers perform operations on

binary number groups called words

Today, most computers use 32- or 64- bit words:


• Words are subdivided into 8-bit groups called bytes.
The Computer Number System 47

The Computer Number System

All computers use the binary system :


• Binary number system: Base = 2.

• Thus there are 2 numbers: 0 and 1.

• A single binary number is called a Binary digIT, or bit.


Computers perform operations on

binary number groups called words

Today, most computers use 32- or 64- bit words:


• Words are subdivided into 8-bit groups called bytes.

• One-half a byte is sometimes referred to as a nibble (a


term not often used anymore).

25/70
Nibbles 48

Nibbles
A nibble is a collection of four bits.
Nibbles 49

Nibbles
A nibble is a collection of four bits.
It wouldn’t be a particularly interesting data structure except
for two items:
Nibbles 50

Nibbles
A nibble is a collection of four bits.
It wouldn’t be a particularly interesting data structure except
for two items:
1 BCD (binary coded decimal) numbers and
2 hexadecimal numbers
Nibbles 51

Nibbles
A nibble is a collection of four bits.
It wouldn’t be a particularly interesting data structure except
for two items:
1 BCD (binary coded decimal) numbers and
2 hexadecimal numbers

It takes four bits to represent a single BCD or hexadecimal


digit.
Nibbles 52

Nibbles
A nibble is a collection of four bits.
It wouldn’t be a particularly interesting data structure except
for two items:
1 BCD (binary coded decimal) numbers and
2 hexadecimal numbers

It takes four bits to represent a single BCD or hexadecimal


digit.

With a nibble, we can represent up to 16 distinct values since


there are 16 unique combinations of a string of four bits:

26/70
Bytes 53

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.
Bytes 54

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.

A byte consists of eight bits


Bytes 55

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.

A byte consists of eight bits

This means that the smallest item that can be individually


accessed by an 80x86 program is an eight-bit value.
Bytes 56

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.

A byte consists of eight bits

This means that the smallest item that can be individually


accessed by an 80x86 program is an eight-bit value.

To access anything smaller requires that you read the byte


containing the data and mask out the unwanted bits.
Bytes 57

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.

A byte consists of eight bits

This means that the smallest item that can be individually


accessed by an 80x86 program is an eight-bit value.

To access anything smaller requires that you read the byte


containing the data and mask out the unwanted bits.
1 The bits in a byte are normally numbered from zero to seven
as shown in Figure
Bytes 58

Bytes

Without question, the most important data structure used by


the 80x86 microprocessor is the byte.

A byte consists of eight bits

This means that the smallest item that can be individually


accessed by an 80x86 program is an eight-bit value.

To access anything smaller requires that you read the byte


containing the data and mask out the unwanted bits.
1 The bits in a byte are normally numbered from zero to seven
as shown in Figure

27/70
Bytes: Two Nibbles 59

Bytes: Two Nibbles

The Two Nibbles in a Byte

28/70
Words 60

Bytes: Two Nibbles

A word is a group of 16 bits.

29/70
Words 61

Bytes: Two Nibbles

A word is a group of 16 bits.

With 16 bits, we can represent 216 (65,536) different values.


These could be the values in the range
1 0..65,535 or,
2 as is usually the case, -32,768..+32,767, or
3 any other data type with no more than 65,536 values
The three major uses for words are
1 signed integer values,
2 unsigned integer values, and
3 UNICODE characters
30/70
Double Words 62

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

31/70
Double Words 63

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

Double words can represent all kinds of different things. A


common item you will represent with a double word is a
32-bit integer value
Double Words 64

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

Double words can represent all kinds of different things. A


common item you will represent with a double word is a
32-bit integer value

These could be the values in the range


Double Words 65

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

Double words can represent all kinds of different things. A


common item you will represent with a double word is a
32-bit integer value

These could be the values in the range

1 unsigned numbers in the range 0..4,294,967,295 or,


Double Words 66

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

Double words can represent all kinds of different things. A


common item you will represent with a double word is a
32-bit integer value

These could be the values in the range

1 unsigned numbers in the range 0..4,294,967,295 or,


2 signed numbers in the range -2,147,483,648..2,147,483,647
or
Double Words 67

Bytes: Two Nibbles

A double word is exactly what its name implies, a pair of words.

Double words can represent all kinds of different things. A


common item you will represent with a double word is a
32-bit integer value

These could be the values in the range

1 unsigned numbers in the range 0..4,294,967,295 or,


2 signed numbers in the range -2,147,483,648..2,147,483,647
or
3 32-bit floating point values also fit into a double word.

32/70
Data Type 68

Figure 1: Bit-numbering and byte-ordering for fundamental data types

33/70
Examples: Binary Numbers 69

Examples: Binary Numbers

A simple electronic switch can represent both binary computer numbers

Used to represent the voltage levels of a digital circuit.


Examples: Binary Numbers 70

Examples: Binary Numbers

A simple electronic switch can represent both binary computer numbers

Used to represent the voltage levels of a digital circuit.

Only two voltage levels present in a digital circuit, Logic


High and Logic Low.
Examples: Binary Numbers 71

Examples: Binary Numbers

A simple electronic switch can represent both binary computer numbers

Used to represent the voltage levels of a digital circuit.

Only two voltage levels present in a digital circuit, Logic


High and Logic Low.

The binary numbers represent the logic low as a 0 and the


logic high as a 1.

34/70
Binary Numbers Representation 72

Binary Numbers Representation

Binary Representations

35/70
Decimal to Binary Conversion
Decimal to Binary Conversion 74

The Computer Number System

A decimal number can be converted to a binary number by


successively dividing the number by 2 as follows:

456710 : 
2 4567 1 

2 2283 1




2 1141 1




2 570 0




2 285 1




2 142 0



2 71 1 = 10001110101112
2 35 1




2 17 1




2 8 0




2 4 0




2 2 0




2 1 1

37/70
Decimal to Binary Conversion 75

The Computer Number System

A decimal number can be converted to a binary number by


successively dividing the number by 2 as follows:

100010 : 
2 1000 0 

2 500 0




2 250 0




2 125 1




2 62 0

= 11111010002
2 31 1 

2 15 1




2 7 1




2 3 1




2 1 1

38/70
Binary to Decimal Conversion 76

Binary to Decimal Conversion

100010012
1 · 20 = 1
0 · 21 = 0
0 · 22 = 0
1 · 23 = 8
0 · 24 = 0
0 · 25 = 0
0 · 26 = 0
1 · 27 = 128
137

39/70
Binary to Decimal Conversion 77
Binary to Decimal Conversion

1000100100100011110000010102
0 · 20 = 0
1 · 21 = 2
0 · 22 = 0
1 · 23 = 8
0 · 24 = 0
0 · 25 = 0
0 · 26 = 0
0 · 27 = 0
0 · 28 = 0
1 · 29 = 512
1 · 210 = 1024
1 · 211 = 2048
1 · 212 = 4096
0 · 213 = 0
0 · 214 = 0
0 · 215 = 0
1 · 216 = 65536
0 · 217 = 0
0 · 218 = 0
1 · 219 = 524288
0 · 220 = 0
0 · 221 = 0
1 · 222 = 4194304
0 · 223 = 0
0 · 224 = 0
0 · 225 = 0
1 · 226 = 67108864
71900682

40/70
Base 9 to Decimal Conversion 78

Base 9 to Decimal Conversion

123456789
8 · 90 = 8
7 · 91 = 63
6 · 92 = 486
5 · 93 = 3645
4 · 94 = 26244
3 · 95 = 177147
2 · 96 = 1062882
1 · 97 = 4782969
6053444

41/70
Base 16 to Decimal Conversion 79

Base 16 to Decimal Conversion

1234567816
8 · 160 = 8
7 · 161 = 112
6 · 162 = 1536
5 · 163 = 20480
4 · 164 = 262144
3 · 165 = 3145728
2 · 166 = 33554432
1 · 167 = 268435456
305419896

42/70
Base 16 to Decimal Conversion 80

Base 16 to Decimal Conversion

F9A70B4672116
1 · 160 = 1
2 · 161 = 32
7 · 162 = 1792
6 · 163 = 24576
4 · 164 = 262144
B · 165 = 11534336
0 · 166 = 0
7 · 167 = 1879048192
A · 168 = 42949672960
9 · 169 = 618475290624
F · 1610 = 16492674416640
17155990251297

43/70
MSB & LSB 81

25 2
1 12 2
0 6 2
0 3 2
1 1

Most significant bit (MSB)


Less significant bit (LSB)

44/70
Converting Decimal to Binary 82

Convert 17910 to a binary.

2 )179
2 )89 · · · · · · 1 LSB
2 )44 ······1
2 )22 ······0
2 )11 ······0
2 )5 ······1
2 )2 ······1
1 ······0
MSB
Thus, the final conversion result is

17910 = 101100112 .

45/70
A Few More Conversions I 83

100010 :  100010 : 
2 1000 0 
 3 1000 1 

2 500 0 3 333 0

 


 

2 250 0 3 111 0

 


 
2 125 1 3 37 1 = 11010013




2 62 0 3 12 0
 

= 11111010002


2 31 1 3 4 1



 

2 15 1 3 1 1

 


2 7 1




2 3 1




2 1 1

46/70
A Few More Conversions II 84

100010 :  100010 : 
4 1000 0 
 5 1000 0 

4 250 2 5 200 0

 

 
4 62 2 = 332204 5 40 0 = 130005
4 15 3 5 8 3

 


 

4 3 3 5 1 1
 

47/70
A Few More Conversions III 85

100010 :  100010 : 
6 1000 4 
 7 1000 6 

6 166 4 7 142 2
 
= 43446 = 26267
6 27 3 
 7 20 6 

6 4 4 7 2 2
 

48/70
A Few More Conversions IV 86

100010 :  100010 : 
8 1000 0 
 9 1000 1 

8 125 5 9 111 3
 
= 17508 = 13319
8 15 7 
 9 12 3 

8 1 1 9 1 1
 

49/70
A Few More Conversions V 87

100010 :  100010 : 
10 1000 0 
 11 1000 10 
10 100 0 11 90 2 = 82A11

= 100010
10 10 0 11 8 8



10 1 1

50/70
A Few More Conversions VI 88

100010 :  100010 : 
12 1000 4  13 1000 12 
12 83 11 = 6B412 13 76 11 = 5BC13
12 6 6 13 5 5
 

51/70
A Few More Conversions VII 89

100010 :  100010 : 
14 1000 6  15 1000 10 
14 71 1 = 51614 15 66 6 = 46A15
14 5 5 15 4 4
 

52/70
A Few More Conversions VIII 90

100010 :  102410 : 
16 1000 8  2 1024 0 

16 62 14 = 3E816 2 512 0




16 3 3 2 256 0
 



2 128 0




2 64 0



2 32 0 = 100000000002
2 16 0




2 8 0




2 4 0




2 2 0




2 1 1

53/70
A Few More Conversions IX 91

102410 :  656110 : 
16 1024 0  3 6561 0 

16 64 0 = 40016 3 2187 0




16 4 4 3 729 0
 



3 243 0



3 81 0 = 1000000003
3 27 0




3 9 0




3 3 0




3 1 1

54/70
A Few More Conversions X 92

100000010 : 
111 1000000 1 
111 9009 18 = 81.18.1.111
111 81 81

100000000010 : 
111 1000000000 1 

111 9009009 27



111 81162 21 = 6.65.21.27.1.111
111 731 65




111 6 6

55/70
A Few More Conversions XI 93

100000000010 : 
7 1000000000 6 

7 142857142 1




7 20408163 6




7 2915451 0




7 416493 0



7 59499 6 = 335316006167
7 8499 1




7 1214 3




7 173 5




7 24 3




7 3 3

56/70
Binary Radix (Base=2) Number System 94

1 Binary radix (base=2) number system is a special case of the


positional number system and used in almost all computers.

57/70
Binary Radix (Base=2) Number System 95

1 Binary radix (base=2) number system is a special case of the


positional number system and used in almost all computers.
2 In this number system, the allowable digits are only 0 and 1 which
are called the bits.

57/70
Binary Radix (Base=2) Number System 96

1 Binary radix (base=2) number system is a special case of the


positional number system and used in almost all computers.
2 In this number system, the allowable digits are only 0 and 1 which
are called the bits.
3 Thus the leftmost digit of a binary number is called the most
significant bit (MSB) and

57/70
Binary Radix (Base=2) Number System 97

1 Binary radix (base=2) number system is a special case of the


positional number system and used in almost all computers.
2 In this number system, the allowable digits are only 0 and 1 which
are called the bits.
3 Thus the leftmost digit of a binary number is called the most
significant bit (MSB) and
4 the rightmost is called the least significant bit (LSB).

57/70
Binary Radix (Base=2) Number System 98

1 Binary radix (base=2) number system is a special case of the


positional number system and used in almost all computers.
2 In this number system, the allowable digits are only 0 and 1 which
are called the bits.
3 Thus the leftmost digit of a binary number is called the most
significant bit (MSB) and
4 the rightmost is called the least significant bit (LSB).
5 Because the base of binary number system is two, the bit di is
associated with the weight 2i .

Example: Binary Numbers

110100102 = 1·27 +1·26 +0·25 +1·24 +0·23 +0·22 +1·21 +0·20 = 21010

1101.00112 = 1·23 +1·22 +0·21 +1·20 +0·2−1 +0·2−2 +1·2−3 +1·2−4 = 13.187510
2 57/70
Number Systems 99

If the base of a number system is larger than ten, the digits


exceeding 9 are expressed using alphabets as a convention.

58/70
Number Systems 100

If the base of a number system is larger than ten, the digits


exceeding 9 are expressed using alphabets as a convention.

1 For example, hexadecimal uses 1-9 and A-F;

58/70
Number Systems 101

If the base of a number system is larger than ten, the digits


exceeding 9 are expressed using alphabets as a convention.

1 For example, hexadecimal uses 1-9 and A-F;


2 base 32 number uses 1-9 and A-V.

58/70
Number Systems 102

If the base of a number system is larger than ten, the digits


exceeding 9 are expressed using alphabets as a convention.

1 For example, hexadecimal uses 1-9 and A-F;


2 base 32 number uses 1-9 and A-V.

One may then wonder that how base-64 numbers are expressed.
Fortunately, we rarely use such high-based numbers because we find
no real advantage of using them.

58/70
Number Systems 103

If the base of a number system is larger than ten, the digits


exceeding 9 are expressed using alphabets as a convention.

1 For example, hexadecimal uses 1-9 and A-F;


2 base 32 number uses 1-9 and A-V.

One may then wonder that how base-64 numbers are expressed.
Fortunately, we rarely use such high-based numbers because we find
no real advantage of using them.

Moreover we can always convert them from any high-base number


to any other low-base number

58/70
Number Systems 104

Table 1 Decimal, binary, hexadecimal, and base-32 Number Systems


Decimal Binary Hexadecimal Base-32
0 00000 0 0
1 00001 1 1
2 00010 2 2
3 00011 3 3
4 00100 4 4
5 00101 5 5
6 00110 6 6
7 00111 7 7
8 01000 8 8
9 01001 9 9
10 01010 A A
11 01011 B B
12 01100 C C
13 01101 D D
14 01110 E E
15 01111 F F
16 10000 10 G
17 10001 11 H
18 10010 12 I
19 10011 13 J
20 10100 14 K
21 10101 15 L
22 10110 16 M
23 10111 17 N
24 11000 18 O
25 11001 19 P
26 11010 1A Q
27 11011 1B R
28 11100 1C S
29 11101 1D T
30 11110 1E U
31 11111 1F V

59/70
Decimal-Octal 105

Decimal Binary Octal


01 0001 001
02 0010 002
03 0011 003
04 0100 004
05 0101 005
06 0110 006
07 0111 007
08 1000 010
09 1001 011
10 1010 012

60/70
Conversion of 2k -Base Number
Systems
Conversion of 2k -Base Number Systems 107

1 The numbers 2k bases have an interesting property in that the


conversion between them can be achieved without the computation
of the equation

m−1
X
D= di · b i .
i=−n

2 Such number systems include binary, octal, hex, and base 32


numbers.
3 Note that since these number systems possess base 2k , all numbers
within these systems can be uniquely represented by k binary bits.
• For example, octal numbers can be represented by three bits;
• hex numbers can be represented by four bits, etc.

4 This relation allows us to easily convert these number systems by


simply grouping their binary representation with k bits.
Conversion of 2k -Base Number Systems: Examples 108

Example: Binary To Hexadecimal Or Octal Conversion

z}|{ z}|{ z}|{


110101102 = 011 010 1102 = 3268
z }|{ z }| {
= 1101 01102 = D616

z}|{ z}|{ z}|{ z}|{ z}|{


11010010.101102 = 11 010 010 . 101 1002 = 322.58
z}| { z}| { z }| {
= 1101 0010 . 10112 = D2.B16

Since the binary representation of 2k base numbers can be directly


associated by simple grouping of k digit strings, the conversion from
octal to hex or vice versa can be also easily achieved.
Conversion of 2k -Base Number Systems: Examples 109
Example: Octal To Hexadecimal or Vice Versa

z}|{ z}|{ z}|{


2738 = 010 111 0112
z}| { z }| {
= 1011 10112
= BB16

z }|{ z }|{ z }| {
AB .D16 = 1010 1011 . 11012
z}|{ z}|{ z}|{ z}|{ z}|{
= 010 101 011 . 110 1002
= 253.648

2
We have seen that the conversion between numbers with power of 2 radix
can be readily achieved through binary expression and regrouping of bits.
This convenience led to the utilization of hexadecimal (or octal) numbers
in representing binary numbers for many computer architecture related
issues.
General Positional Number System
Conversion
Base-k to Base-p Conversion 111

Due to our familiarity and representation of decimals, a convenient way to do a


base-conversion is through the use of decimals. For example, in order to convert a base-k
system to a base-p, we first convert a base-k number to a decimal, then convert the decimal
to a base-p number.

Base − k =⇒ Decimal =⇒ Base − p

Using

m−1
X i
D = di · b .
i=−n

we can easily convert from any base to decimal by simply expressing the digits and weights
using decimal.
Example: Base-k to decimal conversion

3 2 1 0
1BE 816 = 1 · 16 + 11 · 16 + 14 · 16 + 8· = 714410
2 1 0 −1
437.58 = 4·8 +3·8 +7·8 +5·8 = 287.62510

2
66/70
Assignment 113

1 Convert the number 204510 into Binary, Octal, and Hexadecimal Numbers

2 Convert ABCD16 into Binary number

3 Which kind of processor is used in your mobile. Please write a note.

4 Why Base-2 system is important? Please write a note.

5 Apply the equation


m−1
X
D= di · b i
i=−n
on at least 3 Binary, Octal, and Hexadecimal Numbers in each case of your
choice

68/70
References I 114

Computer Systems A Programmer’s Perspective, Randal E. Bryant and David


R. O’Hallaron, 3rd Edition, Pearson Education Limited 2016
Computer Organization and Architecture Designing for Performance by
William Stallings 11th Edition Pearson Education Limited 2019
Lectures Slides by Randy Bryant and Dave O’Hallaron
Computer Organization and Assembly Language by Mr. Muhammad Hafeez

69/70
After all... tomorrow is another day.
(Scarlett O’Hara, “Gone with the Wind”)

You might also like