0% found this document useful (0 votes)
28 views45 pages

Lecture 2

This document discusses number systems used in digital logic and their conversions. It covers: - The 4 main numbering systems: binary, decimal, octal, hexadecimal. - Basic definitions including radix/base, radix point, digits used in each system. - Converting between binary, decimal, octal, and hexadecimal systems using methods like repeated division/multiplication by the base or summing place values. - Why binary is used in computers due to digital switches having two states, and why decimal is used by humans in nature.

Uploaded by

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

Lecture 2

This document discusses number systems used in digital logic and their conversions. It covers: - The 4 main numbering systems: binary, decimal, octal, hexadecimal. - Basic definitions including radix/base, radix point, digits used in each system. - Converting between binary, decimal, octal, and hexadecimal systems using methods like repeated division/multiplication by the base or summing place values. - Why binary is used in computers due to digital switches having two states, and why decimal is used by humans in nature.

Uploaded by

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

Digital Logic

Lecture 2

Number Systems

The Hashemite University


Computer Engineering Department
Outline
 Introduction.
 Basic definitions.
 Number systems types.
 Conversion between different number
systems.
 Counting in different number systems.

The Hashemite University 2


Introduction
 There are 4 numbering systems:
 Binary: 2 digits (0 and 1).
 Decimal: 10 digits (0 – 9).
 Octal: 8 digits (0 – 7).
 Hexadecimal: 16 digits (0 – 9 and A – F).
 The binary system is what used by computers.
 The decimal system is what used by humans in
nature (also called natural number system).
 Hexadecimal and Octal are a compromise
representation between the binary and the
decimal.
The Hashemite University 3
Basic Definitions I
 The number of digits used within a number system is called the
Radix or the Base.
 So:
Binary  Base = 2
Octal  Base = 8
Decimal  Base = 10
Hexadecimal  Base = 16
 The point in the number, i.e. fractional number, is called radix
point. so, based on the radix or base you call it, e.g. in decimal
you call it decimal point and in binary you call it binary point.
 The used digits in each numbering system are borrowed from
the decimal system and completed by the alphabet characters
(capital letters).
 In other words, you are able to use the numerals 0-9 and the
alphabets A-Z based on the number of digits you need. Then
you pick the wanted number of digits in order.
The Hashemite University 4
Basic Definitions II
 For binary, you need two digits, starting from the numerals set (i.e.
0-9) you get 0 and 1 (just two digits). E.g. 10001110.
 For octal, you need 8 digits, following the same approach you get
the digits 0-7. E.g. 756.
 For decimal, you need 10 digits then you get 0-9. E.g. 190.
 For hexadecimal you need 16 digit, starting by the numerals you get
0-9 but still you need an additional 6 digits. For this purpose you
move to the alphabet letters and pick 6 letters, so you get A-F. E.g.
AD4.
 In decimal these letters correspond to the following:
A  10
B  11
C  12
D  13
E  14
F  15
The Hashemite University 5
Basic Definitions III
 To differentiate between numbers from the different numbering
systems use one of the following:
 Add a subscript of the base to the number.
e.g: (1000111)2  Binary
(176)8  Octal
(AD23)16  Hexadecimal
 Add the following letters at the end of the number: B (Binary), Q
(Octal), nothing for Decimal, H (Hexa). E.g. 10010B
 The universal approach to represent hexadecimal numbers is to start
it with a 0 and append ‘h’ to the end of the number. E.g. 0Dh.
 A less common approach to represent binary and hexadecimal
numbers is to proceed the number with a:
% for binary
$ for hexadecimal
e.g. %101001, $AD5
 Any number proceeded by ‘0x’ is a hexadecimal number. Such
representation is most commonly used in programming languages
such as C++.
The Hashemite University 6
Basic Definitions IV
 Every number in any numbering system can be
represented as a weighted sum or a power series of
the system radix.
 The coefficient of each term in the series is the digit
value where the power of the base of that term
depends on the location of the digit within the
number with respect to the decimal point (left or
right).

E.g.: (1890)10 = 1x103 + 8x102 + 9x101 + 0x100

(45.678)10 = 4x101+5x100+6x10-1+7x10-2+8x10-3

(ADF)16 = 10x162 + 13x161 + 15x160
 Note: the result of this power series is the decimal
equivalent of the original number as we will see later.
The Hashemite University 7
Basic Definitions V
 In computer hardware the following are used:
Bit = 0 or 1
Nibble = 4 bits.
Byte = 8 bits
Word = 2 byte = 16 bits
210 = 1 Kilo = 1024
220 = 1 Mega
230 = 1 Giga
240 = 1 Tera
 1 keyboard character needs 1 byte to store its value.
 Every thing in computers is power of 2.
 The architecture of the computer is determined based
on its word length, e.g. 32 bit or 64 bit architecture.
The Hashemite University 8
Basic Definitions VI
 The least significant bit (LSB) is the bit
or digit that is located on the right most
location within a number.
 The most significant bit (MSB) is the bit
that is located on the leftmost position
within a number.
 E.g.: for the number 167829, 1 is the
MSB and 9 is the LSB.

The Hashemite University 9


Why binary system for
computers?
 Computers are comprised basically of
switches.
 Switches have only tow states: either ON or
OFF.
 As we learned, such states can be
represented as two values: 1 and 0.
 So binary since there two values and each
value need one digit or bit to represent each
value or store it.

The Hashemite University 10


Why decimal system for
humans?
 Created with human history on earth and
evolved from nature.
 Easy to understand.
 Compact: need small number of digits to
represent large values.
 Also, humans have invented shorthand or
abbreviations to simplify large decimal
numbers representation to enhance
readability, such as million, billion, trillion,
etc.
The Hashemite University 11
Conversion Between Binary
and Decimal I
 From Binary to Decimal:
 Expand the binary number in a power series and
sum the terms as shown previously.
 The same method is used when there is a radix
point in the number.
 This method can be used to convert from any
base to decimal.
 Examples: the binary value 11001010 represents :
= 1x27 + 1x26 + 0x25 + 0x24 + 1x23 + 0x22 + 1x21 + 0x20
= 1x128 + 1x64 + 0x32 + 0x16 + 1x8 + 0x4 + 1x2 + 0x1
= 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 =202
The Hashemite University 12
Conversion Between Binary
and Decimal II
 From Decimal to Binary:
 Here there are two cases: integer decimal numbers
and fraction (floating point) decimal numbers.
 For integer decimal numbers, there are two methods:
1-Repeated Division By 2
 For this method, divide the decimal number by 2,
 If the remainder is 0, on the right side write down a 0.

 If the remainder is 1, write down a 1.

 Repeat the division with the result (new quotient).

 This process is repeated till the quotient becomes 0.

 When performing the division, the remainders which will

represent the binary equivalent of the decimal number are


written beginning at the least significant digit (right) and
each new digit is written to more significant digit (the left)
The Hashemite University
of the previous digit.13
Integer Decimal to Binary –
First Method -- Example
 Example:
57 / 2 = 28, remainder = 1 (binary number will end with 1)
28 / 2 = 14, remainder = 0
14 / 2 = 7, remainder = 0
7 / 2 = 3,remainder = 1
3 / 2 = 1,remainder = 1
1 / 2 = 0,remainder = 1 (binary number will start with 1)

Therefore, collecting the remainders, 5710 = 1110012

The Hashemite University 14


Integer Decimal to Binary –
Second Method
2- Sum on the fly
 List the powers of 2 starting from 0 power where
you stop at the maximum power less than the
number you want to convert.
 See which of these powers must be included in

the sum that will have the result of the decimal


number that you want to convert.
 These powers will have 1 in its position and the

powers that are not used will have 0.


 This method is suitable for small to mid size

numbers.

The Hashemite University 15


Integer Decimal to Binary –
Second Method -- Example
 Example: convert 5710 to binary

25 24 23 22 21 20

32 16 8 4 2 1

1 1 1 0 0 1

 Answer = 111001
The Hashemite University 16
Fraction Decimal to Binary
 As for integers, for fraction decimal numbers there are
two methods:
1-Repeated Multiplication By 2
 For this method, multiply the decimal number by 2,
 If the integer part of the result is 0, on the right side write

down a 0.
 If the integer part of the result is 1, write down a 1.

 Then remove the integer part from the result and repeat the

multiplication by 2 for the fraction part.


 This process is repeated till the fraction becomes 0 or till you

reach the sufficient accuracy.


 When performing the multiplication, the integers which will

represent the binary equivalent of the decimal fraction are


written beginning from the right of the decimal point and each
new digit is written to less significant digit (the right) of the
previous digit.
The Hashemite University Could be unending!!!!!
17
Fraction Decimal to Binary –
First Method -- Example
 Example: convert 0.310 to binary.

0.3 * 2 = 0.6  integer part = 0


0.6 * 2 = 1.2  integer part = 1
0.2 * 2 = 0.4  integer part = 0
0.4 * 2 = 0.8  integer part = 0
0.8 * 2 = 1.6  integer part = 1
0.6 * 2 = 1.2  integer part = 1, etc.

Answer = 0.010011...
The Hashemite University 18
Fraction Decimal to Binary –
Second Method
2- Sum on the fly
 List the powers of 2 starting from -1 power.
 See which of these powers must be included in
the sum that will have the result of the decimal
number that you want to convert.
 These powers will have 1 in its position and the
powers that are not used will have 0.
 This method is suitable for small to mid size

numbers.

The Hashemite University 19


Fraction Decimal to Binary –
Second Method -- Example
 Example: convert 0.37510 to binary

2-1 2-2 2-3 2-4 2-5 2-6

0.5 0.25 0.125 0.0625 0.03125 0.015625

0 1 1 0 0 0

 Answer = 0.011
The Hashemite University 20
Notes
 The same methods used to convert from
decimal (integer or fraction) to binary are
used to convert from decimal to any other
base. Just change the radix or base value
that you use in the multiplication or in the
division.
 When you face a number that have both
integer and fraction parts, e.g. 107.82 or
1011.11011, convert each part alone and
then combine them.

The Hashemite University 21


Why to introduce the
hexadecimal and the octal (I)?
 Middle approach between binary and decimal
systems:
 Binary are a must by computers but they are
verbose, i.e. need large number of bits to represent
small quantities, e.g. 20210 needs 8 bits in binary.
 Decimal are preferred by humans, easy to
understand and compact (needs small number of
bits to represent values).
 Conversion between binary and decimal (especially
decimal to binary) is not trivial and expensive in
terms of the needed resources.
The Hashemite University 22
Why to introduce the
hexadecimal and the octal (II)?
 To keep commonality with binary system, ease of
conversion, and the compact feature we need
another number system whose base is a power of 2.
 Base 4 is not compact, however, base 8 (octal) and
base 16 (hex) have this feature where base 16 is the
most common.
 From here the hexadecimal system have been
introduced to be a middle approach between binary,
where it is easy to convert between hexa and binary,
as we will see, and the compactness feature as
decimal.
 Recall that computers store data in binary. However,
hexa is commonly used in computers to represent
locations (addresses) in data storage, in data access,
and in RAM. The Hashemite University 23
Conversion Between Binary
and Octal
 The octal has a base = 8 which is 2
raised to power 3. In other words, each
digit in the octal system can substitute
for 3 bits in the binary system.
 Such observation is utilized in the
conversion process between octal and
binary.

The Hashemite University 24


Binary to Octal Conversion
 Start from the radix point to the left and to
the right and do the following:
 Group the binary bits found in the binary number
into groups consist of 3 bits.
 Substitute each group with the octal digit that
represents the same quantity represented by the
binary group.
 The same process are used with the bits on the
right of the radix point (i.e. fraction).

The Hashemite University 25


Binary to Octal Conversion -
Example
• Convert the following number into octal:
10010110101111.10111112

010 010 110 101 111 . 101 111 1002

2 2 6 5 7 . 5 7 48
Answer = 22657.5748
The Hashemite University 26
Octal to Binary Conversion
 Just repeat the inverse of the process used to
convert from binary to octal.
 In other words, substitute each octal digit
with its 3 bit binary equivalent.
 Example: convert 567.428 to binary.
5 6 7 . 4 28

101 110 111 . 100 0102


Answer = 101110111.100010 2
The Hashemite University 27
Octal to Decimal Conversion
 From Octal to Decimal:
 Use the power series expansion method
with the base = 8.
 Example: convert 675.518 to decimal.
= 6x82 + 7x81 + 5x80 + 5x8-1 + 1x8-2
= 445.64062510

The Hashemite University 28


Integer Decimal to Octal
Conversion
 From Integer Decimal to Octal:
 Use the repeated division method used in
converting from decimal to binary but the
difference here is that you divide by 8
(radix value) instead of 2.

The Hashemite University 29


Integer Decimal to Octal
Conversion - Example
 Convert (44978)10 to Octal
Division Quotient Remainder
44978 / 8 5622 2
5622 / 8 702 6
702/8 87 6
87/8 10 7
10/8 1 2
1/8 0 1

 Answer = 1276628
The Hashemite University 30
Fraction Decimal to Octal
Conversion
Repeated Multiplication By 8
 For this method, multiply the decimal number by 8.
 Write down the integer part of the result.

 Then remove the integer part from the result and repeat the

multiplication by 8 for the fraction part.


 This process is repeated till the fraction becomes 0 or till you

reach the sufficient accuracy.


 When performing the multiplication, the integers which will

represent the octal equivalent of the decimal fraction are


written beginning from the right of the decimal point and each
new digit is written to less significant digit (the right) of the
previous digit.
 Could be unending!!!!!

The Hashemite University 31


Fraction Decimal to Octal
Conversion - Example
 Example: convert 0.35610 to octal.

0.356 * 8 = 2.848  integer part = 2


0.848 * 8 = 6.784  integer part = 6
0.784 * 8 = 6.272  integer part = 6
0.272 * 8 = 2.176  integer part = 2
0.176 * 8 = 1.408  integer part = 1
0.408 * 8 = 3.264  integer part = 3, etc.

Answer = 0.266213...8
The Hashemite University 32
Conversion Between Binary
and Hexadecimal
 The Hexa has a base = 16 which 2
raised to power 4. In other words, each
digit in the hexa system can substitute
for 4 bits in the binary system.
 Similar to octal, such observation is
utilized in the conversion process
between hexa and binary.

The Hashemite University 33


Binary to Hexa Conversion
 Start from the radix point to the left and to
the right and do the following:
 Group the binary bits found in the binary number
into groups consist of 4 bits.
 Substitute each group with the Hexa digit that
represents the same quantity represented by the
binary group.
 The same process are used with the bits on the
right of the radix point (i.e. fraction).

The Hashemite University 34


Binary to Hexa Conversion -
Example
• Convert the following number into Hexa:
10010110101111.10111112

0010 0101 1010 1111 . 1011 11102

2 5 A F . B E 16
Answer = 25AF.BE16
The Hashemite University 35
Hexa to Binary Conversion
 Just repeat the inverse of the process used to
convert from binary to hexa.
 In other words, substitute each hexa digit
with its 4 bit binary equivalent.
 Example: convert 56D.4216 to binary.
5 6 D . 4 216

0101 0110 1101 . 0100 00102


Answer = 010101101101.01000010
The Hashemite University 2 36
Hexa to Decimal Conversion
 From Hexa to Decimal:
 Use the power series expansion method
with the base = 16.
 Example: convert 67B.5116 to decimal.
= 6x162 + 7x161 + 11x160 + 5x16-1 +
1x16-2
= 1659.31640610

The Hashemite University 37


Integer Decimal to Hexa
Conversion
 From Integer Decimal to Hexa:
 Use the repeated division method used in
converting from decimal to binary but the
difference here is that you divide by 16
(radix value) instead of 2.

The Hashemite University 38


Integer Decimal to Hexa
Conversion - Example
 Example: Convert 35243 to hexa 10

35243 / 16 = 2202, remainder = 11  B (hex number will end with B)


2202 / 16 = 137, remainder = 10  A
137 / 16 = 8, remainder = 9
8 / 16 = 0, remainder = 8 (hex number will start with 8)

Therefore, collecting the remainders, 3524310 = 89AB16

The Hashemite University 39


Fraction Decimal to Hexa
Conversion
Repeated Multiplication By 16
 For this method, multiply the decimal number by 16.
 Write down the integer part of the result.

 Then remove the integer part from the result and repeat the

multiplication by 8 for the fraction part.


 This process is repeated till the fraction becomes 0 or till you

reach the sufficient accuracy.


 When performing the multiplication, the integers which will

represent the hexa equivalent of the decimal fraction are


written beginning from the right of the decimal point and each
new digit is written to less significant digit (the right) of the
previous digit.
 Could be unending!!!!!

The Hashemite University 40


Fraction Decimal to Hexa
Conversion - Example
 Example: convert 0.35610 to hexa.

0.356 * 16 = 5.696  integer part = 5


0.696 * 16 = 11.136  integer part = B
0.136 * 16 = 2.176  integer part = 2
0.176 * 16 = 2.816  integer part = 2
0.816 * 16 = 13.056  integer part = D
0.056 * 16 = 0.896  integer part = 0, etc.

Answer = 0.5B22D0...16
The Hashemite University 41
Conversion Between Octal and
Hexadecimal
 From octal to hexadecimal:
 First convert from octal to binary then
convert the result from binary to
hexadecimal.
 From hexadecimal to octal:
 First convert from hexa to binary then
convert the result from binary to octal.

The Hashemite University 42


Quick Summary Conversion
Table
Hex
Hex Octal
Octal Binary
Binary Decimal
Decimal
00 00 0000
0000
11 11 0001
0001
 Try to memorize this 22 22 0010
0010
table since it will 33 33 0011
0011
simplify the numbering 44 44 0100
0100
55 55 0101
0101
system conversion 66 66 0110
0110
process on you. 77 77 0111
0111
88 10
10 1000
1000
99 11
11 1001
1001
AA 12
12 1010
1010
BB 13
13 1011
1011
CC 14
14 1100
1100
DD 15
15 1101
1101
EE 16
16 1110
1110
FF 17
17 1111
1111
The Hashemite University 43
Counting Using Numbering
Systems
 Pay attention to the table in the previous slide or
simply use a scientific calculator and start from 0 and
add 1 each time. In all numbering systems track how
counting is done.
 Whenever you reach the largest possible digit value

in a specific numbering system you make it 0 and


add 1 to the higher or more significant digit.
 Example: start counting from 0 in octal as follows:

0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17,


20, ...
 The same is applied for all other numbering systems.

The Hashemite University 44


Additional Notes
 This lecture covers the following
material from the textbook:
 Chapter 1: Sections 1.2 – 1.4

The Hashemite University 45

You might also like