DLD Week#2 &3

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 62

DIGITAL LOGIC &

DESIGN
LEC 2
SIDRA ZUBAIR
2

WHAT IS A BINARY NUMBER?

►A binary number is a number that includes only ones and zeroes.


►The number could be of any length
►The following are all examples of binary numbers

0 10101
1 0101010
10 1011110101
01 0110101110
111000 000111
WHAT IS A DECIMAL NUMBER? 3

► The numbers that we are used to seeing are called decimal numbers.
► decimal numbers consist of the digits from 0 (zero) through 9.
► The following are examples of decimal #'rs

3 76
15 32423234
890 53

► Another name for decimal numbers are base-10 (pronounced "base ten") numbers.
EQUIVALENCE OF BINARY AND 4

DECIMAL
► Every Binary number has a corresponding Decimal value (and
vice versa)

► Examples:

Binary Number Decimal Equivalent


1 1
10 2
11 3
… …
1010111 87
THE VALUE OF A BINARY NUMBER 5

Even though they look exactly the same, the value of the When you see a number that consists of only ones and
binary number, 101, is different from the value of the zeroes, you must be told if it is a binary number or a
decimal number, 101. decimal number.
The value of the binary number, 101, is equal to the decimal number five
(i.e. 5)
The value of the decimal number, 101, is equal to one hundred and one
COMPUTERS STORE
INFORMATION USING
BINARY NUMBERS
ALL INFORMATION ON COMPUTERS IS 7

STORED AS NUMBERS

All information that is processed by Therefore, if we can derive a way to store


computers is converted in one way or and retrieve numbers electronically this
another into a sequence of numbers. method can be used by computers to store
This includes and retrieve any type of information.

numeric information textual information


and Pictures (We’ll see later how text and
pictures can be converted into simple
numbers … for now just take our word
for it.)
HOW DOES A CD STORE 8

INFORMATION?
► For detailed information about a CD works, see the following URL:

http://electronics.howstuffworks.com/cd.htm

► This presentation will only focus on the very basics.


INFORMATION IS STORED USING 9

BINARY NUMBERS
►A binary number is simply a bunch of 1’s and 0’s
►CD’s that are created in a factory (we’re not talking about CD-R’s
yet) may look perfectly flat. However, there are many microscopic
“bumps” on the surface of the CD.
►The bumps are laid out in a spiral form on the surface of the CD.
HOW A
COMPUTER
STORES
INFORMATION
Common types of information Computers Store
BINARY 1
1
Computers use
NUMBERS ARE that are stored by computers are : all information
binary numbers in
AT THE HEART using Binary
OF HOW A different ways to
Whole numbers (i.e. Integers). Numbers
COMPUTER store different
STORES ALL Examples: 8 , 97 -732 etc types of
INFORMATION
Numbers with decimal points. information.
Examples: 3.5 -1.234
0.765 999.001 etc
Textual information (including
letters, symbols and digits
12

►Integers (e.g. 87)

A computer stores integer numbers (i.e. “whole” numbers)


INTEGERS simply as the equivalent binary value for that number.
►Numbers with decimal points (e.g. 87.123)

►Internally, a computer stores a number with a decimal


point as two different integer numbers (each stored using
binary). To get the actual value, the computer performs a
mathematical calculation using the two integers to derive
13

NUMBERS WITH the number.


DECIMAL
POINTS
►We will NOT discuss here the actual mathematical
calculation nor how the computer breaks a number with a
decimal point into two integers.

[NOTE: The two integers are NOT the whole number part
and fractional part.]
►Letters and symbols
►To store letters and symbols, the computer 14

assigns every character on the keyboard a


numerical value.
►Computers remember letters and other symbols
by storing the binary number for the symbol.
LETTERS AND
SYMBOLS ►For this system to work a standard numbering
system needs to be defined and consistently used
for all symbols that the computer needs to
process.

►See the following slide …


15
► ASCII (Americal Some ASCII values (values 1-31 and 128 are not shown)
Standard Code for
Information ► 32 = Space
• 64 = @ • 96 = `
Interchange) is the ► 33 = !
• 65 = A • 97 = a
standard numbering ► 34 = “


66 = B •

98 = b
67 = C 99 = c
given to all characters
► 35 = #

• 68 = D • 100 = d
on a standard
► 36 = $

• 69 = E • 101 = e
keyboard.
► 37 = %

► 38 = & • 70 = F • 102 = f
► 39 = ` • 71 = G • 103 = g
• 72 = H • 104 = h

ASCII (AMERICAN
► 40 = (

• 73 = I • 105 = i
► “ASCII values” range ► 41 = )
• 74 = J • 106 = j
in number from 1 to ► 42 = *

STANDARD CODE FOR


• 75 = K • 107 = k
128. Some “ASCII ► 43 = +
• 76 = L • 108 = l
values” and their ► 44 = ,
• 77 = M • 109 = m
associated symbols
INFORMATION
► 45 = -
• 78 = N • 110 = n
are listed to the right. ► 46 = .
• 79 = O • 111 = o
► 47 = /
• 80 = P • 112 = p

INTERCHANGE)
► 48 = 0
• 81 = Q • 113 = q
► Note that EVERY ► 49 = 1


82 = R •

114 = r
symbol on a standard ► 50 = 2


83 = S
84 = T •
115 = s
116 = t
keyboard has an
► 51 = 3

• 85 = U • 117 = u
ASCII value. Even the
► 52 = 4

• 86 = V • 118 = v
digits 0,1,2,…9 have
► 53 = 5

► 54 = 6 • 87 = W • 119 = w
ASCII values. (see ► 55 = 7 • 88 = X • 120 = x
next slide) ► 56 = 8
• 89 = Y • 121 = y
► 57 = 9
• 90 = Z • 122 = z
► 58 = :
• 91 = [ • 123 = {
► 59 = ;
• 92 = \ • 124 = |
• 93 = ] • 125 = }
► 60 = <
• 94 = ^ • 126 = ~
► 61 = =
• 95 = _
► 62 = >

► 63 = ?
WHY DO 0 THROUGH 9 HAVE ASCII 16

VALUES?
► Numbers that are used in mathematical calculations
► If a computer needs to do math with a number it will store that number using the appropriate binary
representation of the number.
► This makes it easier for the computer to perform mathematical calculations with the number.
► Example: 5 would be stored as
00000101

► Numbers that are NOT used in mathematical calculations


► If the computer does NOT need to do math with the number (e.g. a zip code) then it will generally store
the number using the ASCII values of the digits.
► In this case using the ASCII value is more efficient (for reasons we will not explain here).
► Example 5 would be stored using its ASCII value of 53 which is represented in binary as
00110101
OTHER NUMBERING SYSTEMS 17

(UNICODE AND EBCDIC)

ASCII EBCDIC Unicode


ASCII was the standard numbering Is a different numbering system used Unicode defines a unique number for
system for many years and is still by IBM Mainframe computers. every symbol in all known languages
used widely today. (e.g. Hebrew, Chinese, etc.) and
It is very similar to ASCII but uses commonly used non-letter symbols (e.g.
different numbers to represent the English pound sign, copyright symbol,
symbols. etc).
EBCDIC stands for “Extended Modern programs are moving towards
Binary Coded Decimal Interchange using Unicode to store letters and
Code” symbols.
It should be noted that Unicode
numbers 1-128 correspond to the
EXACT SAME symbols as ASCII 1-
128
HOW TO CONVERT
FROM BINARY TO
DECIMAL
CONVERTING FROM BINARY TO 19

DECIMAL
• Each position for a binary number has a value.
• For each digit, multiply the digit by its position value
• Add up all of the products to get the final result
• The decimal value of binary 101 is computed below:
4 2 1
--------------------------------------
1 0 1

1X1 =1
0X2 =0
1X4 =4

5
WHAT ABOUT A LONGER NUMBER? 20

In general, the "position values" in a binary Example on next slide


number are the powers of two.
The first position value is 20 , i.e. one
The 2nd position value is 2 1 , i.e. two
The 2nd position value is 2 2 , i.e. four
The 2nd position value is 2 3 , i.e. eight
The 2nd position value is 2 4 , i.e. sixteen
etc.
21

SOME TERMINOLOGY ►The following are some terms that are used in the
computer field

►Each digit of a binary number is called a bit.

►A binary number with eight bits (i.e. digits) is called a


byte.
HOW MANY DIFFERENT NUMBERS? 22

There are two different binary numbers There are four different binary numbers
with one bit: with two bits:
0 00 (i.e. decimal 0)
1 01 (i.e. decimal 1)
10 (i.e. decimal 2)
11 (i.e. decimal 3)
►There are eight different binary numbers with three
bits:
►000 (i.e. decimal 0) 23

►001 (i.e. decimal 1)


►010 (i.e. decimal 2) HOW MANY
►011 (i.e. decimal 3) DIFFERENT
►100 (i.e. decimal 4) NUMBERS?
►101 (i.e. decimal 5)
►110 (i.e. decimal 6)
►111 (i.e. decimal 7)
►For n bits there are 2n different binary numbers:

# of bits # of different binary numbers


1 bit: 21 = 2 24

2 bits: 22 = 4
3 bits: 23 = 8
# DIFFERENT NUMBERS - 4 bits: 24 = 16
GENERAL RULE 5 bits: 25 = 32
6 bits: 26 = 64
7 bits: 27 = 128
8 bits: 28 = 256
9 bits: 29 = 512
10 bits: 210 = 1024
etc.
SMALLEST VALUE FOR A BINARY # 25

The smallest value for a binary number of This is the case when all bits are zero:
any number of bits is zero.
SMALLEST VALUE FOR A BINARY # 26

► The smallest value for a binary number with any number of bits is zero (i.e. when all the
bits are zeros)

# of bits smallest binary # decimal value

1 bit: 0 0
2 bits: 00 0
3 bits: 000 0
4 bits: 0000 0
5 bits: 00000 0
6 bits: 000000 0
7 bits: 0000000 0
8 bits: 00000000 0
etc.
LARGEST VALUE FOR A BINARY # 27

The largest value for a binary number with a specific General rule: for a binary number with n bits, the
number of bits (i.e. Digits) is when all of the bits are one. largest possible value is : 2n - 1
►The following are the largest values for binary numbers
with a specific number of bits:

# of bits largest binary# decimal value 28

1 bit: 1 1
2 bits: 11 3
LARGEST NUMBERS 3 bits: 111 7
4 bits: 1111 15
5 bits: 11111 31
6 bits: 111111 63
7 bits: 1111111 127
8 bits: 11111111 255
etc.
CONVERTING A DECIMAL# TO A 29

BINARY# (1)

► Step 1: figure out how many bits you will need


(see the chart on the previous slide).

► Example 1: To convert the decimal number 16 to binary, you will need at least 5 bits.
(With 4 bits you can only store numbers up to 15 but with 5 bits you can store numbers up to 31)

► Example 2: To convert the decimal number 106 to binary, you will need at least 7 bits.
(With 6 bits you can only store numbers up to 63 but with 7 bits you can store numbers up to 127)
CONVERTING A DECIMAL# TO A 30

BINARY# (2)
►Step 2: Keep a chart of the position values and the digits
for your binary number. At first you will not know what
any of the digits will be.

►Example: convert decimal 106 to binary


►step 1 : figure out that you need 7 bits (see earlier slides)
►step 2 : keep track of position values and bits for binary #

64 32 16 8 4 2 1
----------------------------------------------------------------------------------------------------
? ? ? ? ? ? ?
CONVERTING A DECIMAL # TO 31

BINARY (3)
► Step 3: starting with the leftmost digit, see if the position value is greater than, less than or equal to the number you
are trying to convert.
► if the position value is greater than the number then
► make the binary digit in that position zero
► if the position value is less than the number then
► make the binary digit in that position one
► subtract the position value from the decimal # you are trying to convert

► if the position value is equal to the number then


► make the binary digit in that position one
► make the rest of the binary digits zero
► you are done
CONVERTING A DECIMAL # TO 32

BINARY (4)
► Step 4: do step 3 again with the next digit. Keep doing this until you've figured out all of the
digits.
►Example: convert decimal 106 to binary
►Step 1: You need 7 bits (see earlier slides for
explanation).
►Step 2: keep track of position values for bits 33
64 32 16 8
4 2 1

--------------------------------------------------------------------
------------
EXAMPLE ? ? ? ?
? ? ?
►Step 3: Check leftmost position value (i.e. 64)
►64 is less than 105, therefore
►the first binary digit is 1

64 32 16 8
4 2 1

--------------------------------------------------------------------
------------
1 ? ? ?
EXAMPLE (CONTINUED-2) 34

► Step 4: Check next position value (i.e. 32)


► 32 is less than 42, therefore
► the next binary digit is 1
64 32 16 8 4 2 1
-------------------------------------------------------------------------------
1 1 ? ? ? ? ?
► subtract : 64+32=96 <106 => 106-96 =10
► 42 - 32 = 10

► Step 4(continued): Check next position value (i.e. 16)


► 16 is greater than 10, therefore
► 64+32= 96 +16= 112>106
► the next binary digit is 0
64 32 16 8 4 2 1
-------------------------------------------------------------------------------
1 1 0 ? ? ? ?
EXAMPLE (CONTINUED-3) 35

► Step 4(continued): Check next position value (i.e. 8)


► 8 is less than 10, therefore
► the next binary digit is 1
64 32 16 8 4 2 1
-------------------------------------------------------------------------------
1 1 0 1 ? ? ?
► subtract : 10 - 8 = 2

► Step 4(continued): Check next position value (i.e. 4)


► 4 is greater than 2, therefore
► the next binary digit is 0
64 32 16 8 4 2 1
-------------------------------------------------------------------------------
1 1 0 1 0 ? ?
EXAMPLE (CONTINUED-4) 36

► Step 4(continued): Check next position value (i.e. 2)


► 2 is equal to 2, therefore
► the next binary digit is 1

64 32 16 8 4 2 1
-------------------------------------------------------------------------------
1 1 0 1 0 1 ?

► Since the position value was equal to the number (i.e. 2) the rest of the binary digits are all
zeros

64 32 16 8 4 2 1
---------------------------------------------------------------------------
1 1 0 1 0 1 0

► Answer: 1101010
WHY IS IT CALLED "BINARY" (OR 37

BASE-2)?
► The prefix "bi" means "two" in Latin

► Binary derives its name from the fact that the digits in a "Binary" number can only have two
possible values, 0 or 1

► It is also called "base-2" based on the fact that the column values are the powers of 2.
(i.e. 20 21 22 23 24 25 etc. )
COMPUTER CODES

► A computer is a digital system that stores and processes different types of data
in the form of 0s and 1s.

► The different types of data handled by a computer system include numbers,


alphabets and some special characters.

► Therefore, there is a need to change the data entered by the users into a form
that the computer system can understand and process.
COMPUTER CODES

► Different types of codes have been developed and used to represent the data
entered by the users in the binary format.

► The binary system represents each type of data in terms of binary digits, 0s and
1s.

► Since these codes convert the data into the binary form, the computer codes are
also referred as binary codes.
COMPUTER CODES

► Computer professionals use different number systems according to their requirements to


communicate with the computer system.

► All the number systems used by computer professionals to interact with computer systems come
under the category of positional number system.

► The positional number system is a number system in which numbers are represented using
some symbols called digits and the values of these numbers can be determined by taking the
position of digits into consideration.
COMPUTER CODES
The different positional number systems are:

● Decimal system
● Binary system
● Hexadecimal system
● Octal system
DECIMAL SYSTEM

► The decimal system is the most common number system used by human beings.
► It is a positional number system that uses 10 as a base to represent different
values. Therefore, this number system is also known as base 10 number system.
► In this system, 10 symbols are available for representing the values. These
symbols include the digits from 0 to 9. The common operations performed in
the decimal system are addition (+), subtraction (-), multiplication (×), and
division (/).
DECIMAL SYSTEM

► The decimal system can be used to represent both the integer as well as floating
point values. The floating point values are generally represented in this system
by using a period called decimal point.
► The decimal point is used to separate the integer part and the fraction part of the
given floating point number.
► The value of any number represented in the decimal system can be determined
by first multiplying the weight associated with each digit in the given number
with the digit itself and then adding all these values produced as a result of
multiplication operation.
DECIMAL SYSTEM

6543.124

Digit 6 5 4 3 . 1 2 4

Decimal
Weight 103 102 101 100 Point 10-1 10-2 10-3

The powers to the base increases by 1 towards


the left for the integer part and decreases by 1
towards the right for the fraction part.
BINARY SYSTEM

► The binary system uses base 2 to represent different values. Therefore, the
binary system is also known as base-2 system.
► As this system uses base 2, only two symbols are available for representing the
different values in this system. These symbols are 0 and 1, which are also know
as bits in computer terminology.
► Using binary system, the computer systems can store and process each type of
data in terms of 0s and 1s only.
BINARY SYSTEM

The following are some of the technical terms used in binary system:
► Bit: It is the smallest unit of information used in a computer system. It can
either have the value 0 or 1.
► Nibble: It is a combination of 4 bits.
► Byte: It is a combination of 8 bits.
► Word: It is a combination of 16 bits.
► Double word: It is a combination of 32 bits.
► Kilobyte (KB): It is used to represent the 1024 bytes of information.
► Megabyte (MB): It is used to represent the 1024 KBs of information.
► Gigabyte (GB): It is used to represent the 1024 MBs of information.
BINARY SYSTEM
► We can determine the weight associated with each bit in the given binary
number in the similar manner as we did in the decimal system.
► In the binary system, the weight of any bit can be determined by raising 2 to
a power equivalent to the position of bit in the number.

1011.101

Digit 1 0 1 1 . 1 0 1

Binary
Weight 23 22 21 20 Point 2-1 2-2 2-3
HEXADECIMAL SYSTEM

► The hexadecimal system is a positional number system that uses base 16 to


represent different values. Therefore, this number system is known as base-16
system.
► As this system uses base 16, 16 symbols are available for representing the
values in this system. These symbols are the digits 0-9, which are used to
represent the decimal values 0 through 9, and the letters A, B, C, D, E and F,
which are used to represent the decimal values 10 through 15.
HEXADECIMAL SYSTEM

► The weight associated with each symbol in the given hexadecimal number can be determined
by raising 16 to a power equivalent to the position of the digit in the number.

4A90.2BC

Digit 4 A 9 0 . 2 B C

Hexadecimal
Weight 163 162 161 160 Point 16-1 16-2 16-3
OCTAL SYSTEM

► The octal system is the positional number system that uses base 8 to represent
different values. Therefore, this number system is also known as base-8 system.

► As this system uses base 8, eight symbols are available for representing the
values in this system. These symbols are the digits 0 to 7.
OCTAL SYSTEM

► The weight associated with each digit in the given octal number can be determined by raising 8
to a power equivalent to the position of the digit in the number.

2157.075

Digit 2 1 5 7 . 0 7 5

Octal
Weight 8 3
82
81
80
Point 8-1 8-2 8-3
CONVERSION OF NUMBERS

► The computer systems accept the data in decimal form, whereas they store and
process the data in binary form. Therefore, it becomes necessary to convert the
numbers represented in one system into the numbers represented in another
system. The different types of number system conversions can be divided into the
following major categories:

• Non-decimal to decimal
• Decimal to non-decimal
• Octal to hexadecimal
NON-DECIMAL TO DECIMAL

► The non-decimal to decimal conversions can be implemented by taking the


concept of place values into consideration. The non-decimal to decimal
conversion includes the following number system conversions:

• Binary to decimal conversion


• Hexadecimal to decimal conversion
• Octal to decimal conversion
BINARY TO DECIMAL CONVERSION

► A binary number can be converted to equivalent decimal number by calculating


the sum of the products of each bit multiplied by its corresponding place value.
► Examples 6.14 and 6.17, p110.
► 6.14: Convert the binary number 10101101 into its corresponding decimal
number.
(1×27)+(0×26)+(1×25)+(0×24)+(1×23)+(1×22)+ (0×21)+(1×20)
=128+0+32+0+8+4+0+1
=173
HEXADECIMAL TO DECIMAL
CONVERSION
► A hexadecimal number can be converted into its equivalent number in decimal
system by calculating the sum of the products of each symbol multiplied by its
corresponding place value.
► Examples 6.20 and 6.22, p111.
► 6.20: Convert the hexadecimal number 6B39 into its equivalent in the decimal
system.
(6×163)+(11×162)+(3×161)+(9×160)
=24567+2816+48+9
=27449
OCTAL TO DECIMAL CONVERSION

► An octal number can be converted into its equivalent number in decimal system
by calculating the sum of the products of each digit multiplied by its
corresponding place value.
► Examples 6.25 and 6.28, p113.
► 6.25: Convert the octal number 13256 into its equivalent in decimal systems.
(1×84)+(3×83)+(2×82)+(5×81)+(6×80)
=4096+1536+128+40+6
=5806
DECIMAL TO NON-DECIMAL

► The decimal to non-decimal conversions are carried out by continually dividing


the decimal number by the base of the desired number system till the decimal
number becomes zero. After the decimal number becomes zero, we may note
down the remainders calculated at each successive division from last to first to
obtain the decimal number into the desired system. The decimal to non-decimal
conversion includes the following number system conversions:

• Decimal to binary conversion


• Decimal to hexadecimal conversion
• Decimal to octal conversion
DECIMAL TO BINARY CONVERSION

► The decimal to binary conversion is performed Decimal Divisor Quotient Remainder


by repeatedly dividing the decimal number by 2 Number
till the decimal number becomes zero and then 30 2 15 0
reading the remainders from last to first to 15 2 7 1
obtain the binary equivalent to of the given 7 2 3 1
decimal number. 3 2 1 1
► Examples 6.29 and 6.30, p114. 1 2 0 1

► 6.29: Convert the decimal number 30 into its Now, read the remainders calculated in
equivalent binary number. the above table in upward direction to
obtain the binary equivalent, which is
11110. Therefore, the binary equivalent
of the decimal number 30 is 11110.
DECIMAL TO HEXADECIMAL
CONVERSION
► The decimal to hexadecimal conversion is Decimal Divisor Quotient Remainder
performed by repeatedly dividing the decimal Number
number by 16 till the decimal number becomes 1567 16 97 15(F)
zero and then reading the remainders form last 97 16 6 1
to first to obtain the binary equivalent to of the 6 16 0 6
given decimal number.
► Examples 6.34, p116: Convert the decimal Now, read the remainders
number 1567 into its equivalent hexadecimal calculated in the above table in
number. upward direction to obtain the
hexadecimal equivalent, which is
61F. Therefore, the hexadecimal
equivalent of the decimal number
1567 is 61F.
DECIMAL TO OCTAL CONVERSION

► The decimal to octal conversion is performed Decimal Divisor Quotient Remainder


Number
by repeatedly dividing the decimal number by
45796 8 5724 4
8 till the decimal number becomes zero and
then reading the remainders form last to first 5724 8 715 4
to obtain the binary equivalent to of the given 715 8 89 3
decimal number. 89 8 11 1
11 8 1 3
1 8 0 1
► Examples 6.36, p117: Convert the decimal
number 45796 to its equivalent octal number. Now, read the remainders calculated
in the above table in upward direction
to obtain the octal equivalent, which
is 131344. Therefore, the octal
equivalent of the decimal number
45796 is 131344.
OCTAL TO HEXADECIMAL

► The given octal number can be converted into its equivalent hexadecimal
number in two different steps:
• (1) Convert the given octal number into its binary equivalent by representing
each digit in the octal number to its equivalent 3-bit binary number.
• (2) Divide the binary number into 4-bit sections starting from the least
significant bit.
OCTAL TO HEXADECIMAL

• Example 6.38, p119: Convert the octal number 365 into its
equivalent hexadecimal number.

3 6 5

011 110 101

0000 1111 0101

0 F 5
Therefore, the equivalent hexadecimal number is F5.

You might also like