Professional Documents
Culture Documents
DLD Week#2 &3
DLD Week#2 &3
DLD Week#2 &3
DESIGN
LEC 2
SIDRA ZUBAIR
2
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:
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
INFORMATION?
► For detailed information about a CD works, see the following URL:
http://electronics.howstuffworks.com/cd.htm
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
[NOTE: The two integers are NOT the whole number part
and fractional part.]
►Letters and symbols
►To store letters and symbols, the computer 14
• 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 = *
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
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
SOME TERMINOLOGY ►The following are some terms that are used in the
computer field
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
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)
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:
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)
► 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.
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
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
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.
► 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
► 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 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 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
► 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
► 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 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
0 F 5
Therefore, the equivalent hexadecimal number is F5.