Nothing Special   »   [go: up one dir, main page]

Introduction To Number Systems Commonly Used Number Systems Conversion of Number Systems Data Representation Encoding System

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

Course Outline

Introduction to Number Systems

Commonly Used Number Systems

Conversion of number systems

Data representation

Encoding System

05/13/2021 Compiled by computer science department 1


Introduction
 Data is stored in a format that cannot be easily read by human beings.
 Every computer stores numbers, letters, and other special characters in a coded form.
 A number system is a set of codes which are given to distinct values or quantities.
 Assigned codes (symbols) we will ‘count’.
 The symbols are called digits.
 Generally, a number system is characterized by:
 Its base (radix): The number of digits that are included in the number system.
 Its digits : A decimal number system is the system that we always use in our day-Today
activities.
 It contains 0,1,2,3,4,5,6,7,8,9 and as a result its base (number of digits) is 10.

05/13/2021 Compiled by computer science department 2


Introduction…
 Number systems to understand the operations of computers.
 Computer operations can be divided in to two as Arithmetic and Logical.

 Arithmetic operations are operations involving arithmetic calculations like addition,


subtraction, multiplication and division.
 Logical operations are operations that do not directly relate with numbers.
 They consist of comparisons.
 A very simple example of logical expression can be 2>3, Yes/No'.
 whatever the type of operation is, computers understand only 0 and 1.

05/13/2021 Compiled by computer science department 3


Introduction…
 Number systems are basically two types: non positional and positional.
Non positional number systems
 In early time, human beings counted on fingers.
 When ten fingers were not adequate, stones, or sticks were used to indicate values.
 This method of counting uses an additive approach or the non–positional number system.
 In this system, we have symbols such as I for 1, II for 2, III for 3, IIII for 4, IIIII for 5,
etc.
 Each symbol represents the same value regardless of its position in the number and the
symbols are simply added to find out the value of a particular number.
 Since it is very difficult to perform arithmetic with such a number system, positional
number systems were developed as the centuries passed.

05/13/2021 Compiled by computer science department 4


Introduction…
Positional number systems
 There are only a few symbols called digits, and these symbols represent different values
depending on the position they occupy in the number.
 The value of each digit in such a number is determined by three considerations:
1. The digit itself,
2. The position of the digit in the number, and
3. The base of the number system
 The number system that we use in our day today life is called the Decimal number
system.
 The base is equal to 10 because there are altogether ten symbols or digits
(0,1,2,3,4,5,6,7,8,9) used in this system.

05/13/2021 Compiled by computer science department 5


Introduction…
Cont…
 In the decimal system, the successive positions to the left of the decimal point represent units, tens,
hundreds, thousands, etc.
 But you may not have given much attention to the fact that each position represents a specific power
of the base (10).
 For example, the decimal number 2586 (written as 2586 10),
 6=unit position
 8= tenth position
 5=hundreds position
 2=thousands position
• the value can be written as:
  (2 x 1000) + (5 x 100) + (8 x 10) + (6 x1)
or 2000 + 500 + 80 + 6
or 2586
05/13/2021 Compiled by computer science department 6
Introduction…
Cont…
 It may also be observed that the same digit signifies different values depending on the
position it occupies in the number.
For example,
• In 258610 the digit 6 signifies 6 x 100 = 6
• In 256810 the digit 6 signifies 6 x 101 = 60
• In 265810 the digit 6 signifies 6 x 102 = 600
• In 628510 the digit 6 signifies 6 x 103 = 6000
 There are two characteristics of all number systems that are suggested by the value of the
base.
 The first of these choices is always zero.
 The second characteristic is that the maximum value of a single digit is always equal
to one less than the value of the base.

05/13/2021 Compiled by computer science department 7


Commonly Used Number Systems
1. The Decimal Number System
 The decimal number system is a system containing 10 digits 0, 1, 2..., 9.
 That is our familiar number system.
 The base or radix of the decimal number system is 10.
 The value of the first digit of the number from the right side is first digit * 100.
 The value of the second digit of the number from the right side is second digit * 101.
 The value of the third digit of the number from the right side is third digit * 102 etc.
 The value of the nth digit of the number from the right side is n digit * 10n etc.

05/13/2021 Compiled by computer science department 8


Commonly Used Number Systems…
Example: 1: 12 contains two digits 1 and 2.
 If the digits are written separately, then the value of 1 is just one (single) and the value of
2 is two (pair).
 But as you can see when they are written together, the value of 1 is to mean 10 and the
value of 2 is 2.
12= 10+2
 Every digit of a decimal number system has its own value (weight).
 The weight of a digit will depend on its position.
Example2: Compare the value of 4 in the following two numbers: 435 and 248.
435 = 400 + 30 + 5 = 4 X 102 + 3 x 101 + 5 x 100
248 = 200 + 40 + 8 = 2 X 102 + 4 x 101 + 8 x 100
The weight of 4 in 435 is 400 and in 248 is 40.
Generally, the weight of each digit in a decimal number is given by:

Weight (nth digit) = n th digit x (10) n-l

05/13/2021 Compiled by computer science department 9


Commonly Used Number Systems…
 Base = given base of the number system
 Actually 'n' should be counted starting from right and starting with 1 and continuing with
2,3 etc. to the left. to use the above formula.
 But the best (shortest) way is to start with 0 instead of 1 when counting even if the
assigned numbers will not represent the real position of the digits since there is no
a 0 position.
Example: 356789.
6 5 4 3 2 l ------- Position
3 5 6 7 8 9 ----- Decimal number
Weight (1lst digit) = 1st digit X (10)1-1 =9xl0o =9xl=9
Weight (2nddigit) = 2nd digit x (10)2-1 = 8x 101 = 8 x 10 = 80
Weight (3rddigit) = 3rd digit (10)3-1 =7xl02 =7xl00=700

05/13/2021 Compiled by computer science department 10


Commonly Used Number Systems…
Cont…
 If the number is a fraction decimal number, then the weight of the digits after the decimal point will
be calculated as:
 Where n: position of the digit after the decimal point when it is counted to the right starting from the
immediate digit after the decimal point and With the value negative one(-1).
  Base: the given base of the number system
  Weight (n th digit) = n th digit x (Base) -n
 
Example4: “0.125”
Solution:
-1 -2 -3 --- Position
0.125 -------- Decimal fraction
 Weight (l st digit) = 1st digit X 10-1 = 1 x 10-1 = 10-1= 0.1
 Weight (2nd digit) = 2nd digit X 10-2 = 2 x 10-2 = 0.02
 Weight (3rd digit) = 3rd digit X10-3 = 5x10-3=0.005
05/13/2021 Compiled by computer science department 11
Commonly Used Number Systems…
2. Binary number system
 Exactly like the decimal system except that the base is 2 instead of 10.
 We have only two symbols or digits (0 and 1) that can be used in this number system.
 Note that the largest single digit is 1 (one less than the base).
 Each position in a binary number represents a power of the base (2).
 The rightmost position in the units (20) position, the second position from the right is the
2’s (21) position and proceeding in this way we have 4’s (22) position, 8’s (23)
position,16’s (24) position, and so on.
 Example, 10101 (written as 101012) is
  (1x24) + (0x23) + (1x22) + (0x21) + (1x20)
or 16 + 0 + 4 + 0 + 1
or 21
 So we have 101012 = 2110
05/13/2021 Compiled by computer science department 12
Commonly Used Number Systems…
Cont…
 “Binary digit” is often referred to by the common abbreviation bit.
 Thus, a “bit” in computer terminology means either a 0 or a 1.
 A binary number consisting of n bits is called an n-bit number.
 The following table lists all the 3-bit numbers along with their decimal equivalent.
Binary Decimal
Equivalent
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

05/13/2021 Compiled by computer science department 13


Commonly Used Number Systems…
3. Octal number system
 There are only 8 symbols or digits: 0,1,2,3,4,5,6, and 7 (8 and 9 do not exist in this
system).
 The largest single digit is 7 (one less than the base).
 Again, each position in an octal number represents a power of the base (8).
Example: 2057 (written as 20578) is:
  (2x83) + (0x82) + (5x81) + (7x80)
or 1024 + 0 + 40 + 7
or 1071
 So we have 20578 = 107110
 Observe that since there are only 8 digits in the octal number system, so 3 bits (2 3 = 8) are
sufficient to represent any octal number in binary as shown in the above table.

05/13/2021 Compiled by computer science department 14


Commonly Used Number Systems…
4. Hexadecimal number system
 The base of 16 suggests choices of 16 single character digits or symbols.
 The first 10 digits are the digits of a decimal system 0,1,2,3,4,5,6,7,8,9.
 The remaining six digits are denoted by A,B,C,D,E,F representing the decimal values
10,11,12,13,14,15 respectively.
 Thus, largest single digit is F or 15 (one less than the base).
Example: 1AF (written as 1AF16) is:
 (1x162) + (Ax161) + (Fx160)
or (1x256) + (10x16) + (15x1)
or 256 + 160 +15=431
So we have, 1AF=43110
 Observe that since there are only 16 digits in the hexadecimal number system, so
4 bits (24 = 16) are sufficient to represent any hexadecimal number in binary.
05/13/2021 Compiled by computer science department 15
Commonly Used Number Systems…
Conversion of decimal numbers into any other number systems

  Converting a number from the decimal number system into any other number system, separate it
into integer part (left side of the decimal point) and fraction part (right side of the decimal point).

 For the integer part, the following procedure is followed:

1. Divide the integral part of the decimal number by the base of the target number system and note the
remainder.
2. Divide the quotient of the previous division by the base of the target number system and note the
remainder.
3. Repeat step 2 till the quotient becomes 0.
4. Arrange the remainders in an order starting with the last division.
5. The number obtained in step 4 is the integer part of the desired number.
 
05/13/2021 Compiled by computer science department 16
Commonly Used Number Systems…
Cont…
 For the fraction part, the following procedures are followed:
 
1. Multiply the fraction part by the base of the system and note the integer part of the result.
2. Multiply the fraction part of the previous result by the base of the system and note the
integer part of the result.
3. Repeat step 2 till the fraction part of the result is zero or till the required accuracy
(number of digits after the decimal point) is achieved.
4. Arrange the integer parts in the order starting with first multiplication.
5. The number obtained in step 4 is the fraction part of the desired number.

05/13/2021 Compiled by computer science department 17


Commonly Used Number Systems…
Cont…
Example 1 b) Conversion into an octal number:
Convert the decimal number 93 into:
93 / 8, Q = 11, R = 5
11 / 8, Q = 1, R = 3
a) binary numbers 1 / 8, Q = 0, R = 1
b) octal numbers
c) hexadecimal number Therefore, an equivalent octal number = 135
Solution c) Conversion into a hexadecimal number:
a) Conversion into a binary number:- 93/16, Q=5, R=13=D
93 / 2, Q = 46, R = 1 5/16, Q=0, R=5
46 / 2, Q = 23, R = 0 Therefore, an equivalent hexadecimal number is 5D
23 / 2, Q = 11, R = 1
11 / 2, Q = 5, R = 1 Example 2
5 / 2, Q = 2, R = 1 Convert 0.125 from decimal to binary
Solution: - 0.125 x 2 = 0.250 here the integer part is 0
2 / 2, Q = 1, R = 0
0.250 x 2 = 0.50 here the integer part is 0
1 / 2, Q = 0, R = 1 0.50 x 2 = 1.0 here the integer part is 1
Since the fraction part is 0, no further multiplication is
Therefore, an equivalent binary number becomes 1011101 required. So, an equivalent binary number becomes 0.001
That is, (0.125)10 = (0.001)2

05/13/2021 Compiled by computer science department 18


Commonly Used Number Systems…
Conversion of other systems into decimal number system
A number in the non- decimal number system is converted into a decimal number by
multiplying each digit in the number by its place value and adding all the products.
Example 1
 Convert the hexadecimal number FA2E into a decimal number
Solution:
FA2E = (F x 163) + (A x 162) + (2 x 161) + (E x 160)
= (15 x 4096) + (10 x 256) + (2 x 16) + (14 x 1)
= 61440 + 2560 + 32 + 14
= 64046
Therefore, FA2E16 = 6404610

05/13/2021 Compiled by computer science department 19


Commonly Used Number Systems…
Cont…
Example 2
 Convert the octal number 765 into a decimal number
Solution:
765 = (7 x 82) + (6 x 81) + (5 x 80)
= (7 x 64) + (6 x 8) + (5 x 1)
= 448 + 48 + 5
= 501
Therefore, 7658 = 50110
 Example 3
Convert the binary number 101.01 into a decimal number
Solution:
101.01 = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2)
= 4 + 0 + 1 + 0 + 0.25
= 5.25
Therefore, (101.01)2 = 5.2510
05/13/2021 Compiled by computer science department 20
Commonly Used Number Systems…
Converting from a base other than 10 to a base other than 10
The following two steps are used to convert a number from a base other than 10 to a base other than 10.
Step 1: Convert the original number to a decimal number (base 10).
Step 2: Convert the decimal number so obtained to the new base.
Example 1. 5456 = ?4
Step 2: Convert 20910 to base 4
Solution:
Step 1: Convert from base 6 to base 10 209 / 4, Q = 52, R = 1
545 = (5 x 62) + (4 x 61) + (5 x 60) 52 / 4, Q = 13, R = 0
= (5 x 36) + (4 x 6) + (5 x 1) 13 / 4, Q = 3, R = 1
= 180 + 24 + 5 3 / 4, Q = 0, R = 3
= 209
Therefore, 5456 = 20910 Hence, 20910 = 31014
So, 5456 = 20910 = 31014
Thus, 5456 = 31014

05/13/2021 Compiled by computer science department 21


Commonly Used Number Systems…
Shortcut method for binary to octal conversion
The following steps are used in this method:
Step 1: Divide the binary digits into groups of three (starting from the right).
Step 2: Convert each group of three binary digits into one octal digit.

 There are only 8 digits (0 to 7) in the octal number system, so 3 bits (23 = 8) are
sufficient to represent any octal number in binary).
 Since decimal digits 0 to 7 are equal to octal digits 0 to 7 so binary to decimal
conversion can be used in this step.

05/13/2021 Compiled by computer science department 22


Commonly Used Number Systems…
Cont…
Example 1. 1011102 = ?8
 Solution:
Step 1: Divide the binary digits into groups of 3 starting from right
101 110
Step 2: Convert each group into one digit of octal (use binary-to-decimal conversion)
 

05/13/2021 Compiled by computer science department 23


Commonly Used Number Systems…
Shortcut method for binary to hexadecimal conversion

Step 1: Divide the binary digits into groups of four (starting from the right).

Step 2: Convert each group of four binary digits to one hexadecimal digit.

 Remember that hexadecimal digits 0 to 9 are equal to decimal digits 0 to 9, and


hexadecimal digits A to F are equal to decimal digits 10 to 15.

 The binary to decimal conversion procedure can be used, but the decimal values 10 to 15
must be represented as hexadecimal A to F.
 

05/13/2021 Compiled by computer science department 24


Commonly Used Number Systems…
Cont…

05/13/2021 Compiled by computer science department 25


Commonly Used Number Systems…
Shortcut method for octal to binary conversion
The following steps are used in this method:
Step 1: Convert each octal digit to a 3 digit binary number. (The octal digits may be
treated as decimal for this conversion).
Step 2: Combine all the resulting binary groups (of 3 digits each) into a single binary
number.

05/13/2021 Compiled by computer science department 26


Commonly Used Number Systems…
Shortcut method for hexadecimal to binary conversion
Step 1: Convert the decimal equivalent of each hexadecimal digit to 4 binary digits.
Step 2: Combine all the resulting binary groups (of 4 digits each) into a single number.
 

05/13/2021 Compiled by computer science department 27


Commonly Used Number Systems…
Summary
 Relationship between the decimal, binary, hexadecimal, and octal number systems. Note
that the maximum value for a single digit of octal (7) is equal to the maximum value of
three digits of binary.
 The value range of one digit of octal duplicates the value range of three digits of binary.
 If octal digits are substituted for binary digits, the substitution is on a one-to-three basis.
Thus, computers that print octal numbers instead of binary, while taking memory dump,
save one-third of the printing space and time.
 The maximum value of one digit in hexadecimal is equal to the maximum value of four
digits in binary.
 The value range of one digit of hexadecimal is equivalent to the value range of four digits
of binary.
 Therefore, hexadecimal shortcut notation is a one-to-four reduction in the space and time
required for memory dump.

05/13/2021 Compiled by computer science department 28


Commonly Used Number Systems…
Cont…
Hexadecimal Binary(for hexadecimal) Octal Corresponding binary(for octal)
0 0000 0 000
1 0001 1 001
2 0010 2 010
3 0011 3 011
4 0100 4 100
5 0101 5 101
6 0110 6 110
7 0111 7 111
8 1000  
9 1001  
A 1010  
B 1011  
C 1100  
D 1101  
E 1110  
F 1111  
05/13/2021 Compiled by computer science department 29
Data representation
Computer is a data processing machine, so we have to understand the nature
of data.
Data can be found in different forms like as a number, text, images audio &
video.
A computer uses universal uniform representations of data is known as Bit
Patterns.
Bit pattern is a sequence or strings of bits that is used to represent different
data types.
Bit:
Bit (Binary Digit) is the smallest unit of data that can be stored in a computer.
It is a single bit that can be stored in a computer.

05/13/2021 Compiled by computer science department 30


Data representation…
Byte:
The most important data structure used by the most microprocessor is the byte.
A byte consists of eight bits and is the smallest addressable datum (data item) in the
microprocessor.
It is the most important data structure & is used by most microcomputer.
The bits in a byte are numbered from bit zero (b0) through seven (b7) as follows:

b7 b6 b5 b4 b3 b2 b1 b0

Byte contains eight bits, it can represent 28, or 256, different values.

05/13/2021 Compiled by computer science department 31


Data representation…
Generally, we'll use a byte to represent:
1. unsigned numeric values in the range 0 to 255
2. signed numbers in the range -128 to +127
3. ASCII character codes
4. Other special data types requiring no more than 256 different values.
 Many data types have fewer than 256 items so eight bits is usually sufficient.
Word:
 group of bits greater than or equal to 8 bits.
There is no fixed size for a word length.
It depends on from computer to computer.
Most micro processors & minicomputers are normally byte oriented with word
length 8 bits, 16 bits 32 bits & 64 bits.

05/13/2021 Compiled by computer science department 32


Encoding System
In a character representation, a single character should be represented the given number of
bits of that coding scheme.
The most commonly used coding to represent characters are:
 
BCD (Binary Coded Decimal)
 EBCDIC (Extended Binary Coded Decimal Interchange Code)
ASCII -7 and ASCII-8 (American Standard Code for Information Interchange)

05/13/2021 Compiled by computer science department 33


BCD (Binary Coded Decimal)
This is the simplest coding scheme.
Used four bits to represent each digit of the decimal number into its binary
equivalent rather than converting the entire decimal value into a pure binary form.
Example: The code of the digit 1 is 0001
The code of the digit 4 is 0100.
Example: The code of the digit 43 is 01000011
Note that each decimal digit is independently converted to a 4 bit binary
number.
However 4 bits are insufficient to represent the various characters used by
a computer system.
Instead of using 4 bits with only 16 possible characters, computer designers
commonly 6 bits to represent characters in BCD.

05/13/2021 Compiled by computer science department 34


BCD (Binary Coded Decimal)…
In the 6 bit BCD code the 4 BCD numeric place positions are retained but
additional zone positions are added.
it is possible to represent 64 (26) different characters.
This is a sufficient number to code the decimal digits (10), alphabetic
letters(26), and other special characters (28).
Note: In addition to the four bits that represent the actual data, additional two
bits are used as zone bits.
BCD (zone bits of each group) Letters/Digits Represented
11 A_I
10 J_R
01 S_Z
00 0_9

05/13/2021 Compiled by computer science department 35


BCD (Binary Coded Decimal)…
Example :
In 6 Bit BCD representation, 0001 is used to represent three characters, letter A, letter J
Or digit 1.
The digit 1 is represented as 000001.
The letter A is represented as 110001.
The letter J is represented as 100001.

05/13/2021 Compiled by computer science department 36


BCD (Binary Coded Decimal)…
Example1: Represent F in BCD.
Solution: In which range is it found? It is in the range A -I.
So the zone bits are determined as 11.
F is the sixth letter if you count starting from A. So, it will be represented by the decimal form of the
digit which is 110 (or 0110 using 4 digits).
Finally, the representation of F in BCD is 110110.
Example2: show the binary digits used to record the word BASE in 6 bit BCD code.
 Solution:
B = 110010 in BCD binary notation
A = 110001 in BCD binary notation
S = 010010 in BCD binary notation
E = 110101in BCD binary notation
So the binary digits
110010 110001 010010 110101
B A S E
05/13/2021 Compiled by computer science department 37
EBCDIC (Extended Binary Coded Decimal Interchange Code)
To make the number of characters represented by BCD more, 2 bits are added to the 6 bits
(totally 8 bits).
This makes the improved BCD capable of representing 28 (256) characters.
EBCDIC is developed by IMB; it is an 8 bits pattern.
The only difference between BCD and EBCDIC is their zone bits.
Unlike BCD, EBCDIC uses 4 zone bits and the following table shows you the equivalent
zone bits of EBCDIC to the BCD zone bits.
EBCDIC(zone bits of each group) Letters/Digits Represented
  1100 A_I
1101 J_R
1110 S_Z
1111 0_9

05/13/2021 Compiled by computer science department 38


ASCII -7 and ASCII-8 (American Standard Code for Information Interchange)

 The other popular schemes are ASCII -7 and ASCII-8.

 ASCII-8 is an extended version of ASCII-7.

Generally, ASCII-7 code was designed as a standard code for ISO (International
Organization for Standardization).

 It is a 7-bit code and as a result representing 27(128) characters.

 From the 7-bits, 3-bits are used as zone bits and the other four bits represent the actual
data. ASCII is a little bit different from the BCD and EBCDIC because in ASCII
alphabetical letters are divided into two sections, not three.

05/13/2021 Compiled by computer science department 39


ASCII -7 and ASCII-8 …
Zone bits ASCII-7 representation of Letters/ Digits
100 A_O
101 P_Z
011 0_9

Example: Represent the letter A in ASCII.


Solution: Since A is in the range A_O and therefore the zone bits used must be 0100.
So, the representation of letter A in ASCII will be 1000001.
 ASCII-8:
ASCII -8 is an extended version of ASCII-7, which uses 8 bits rather than 7 bits.
ASCII-8 can represent 28(256) possible characters.
The difference between ASCII-7 & ASCII -8 is that only on their zone bits.
ASCII-8 uses 4 bits as a zone bit.

05/13/2021 Compiled by computer science department 40


Quiz weight 10 %
1. Convert the decimal number 82 into:
a) binary numbers b)octal numbers c) hexadecimal number
2. Convert the hexadecimal number 1CF into decimal
3. Find weight of each digit in a decimal number of the following
a) 2745 b) 0.275
4. List the largest single digit of Commonly Used Number System of the
following:- a) Binary b) decimal c) octal d) hexadecimal
5. Show the binary digits used to represent C in BCD.
6. Show the binary digits used to record the word ICT in 6 bit BCD code.
7. Show the binary digits used to represent the letter F in ASCII
05/13/2021 Good luck!!
Compiled by computer science department
41
?? ?? ??
?? ? ?

05/13/2021 Compiled by computer science department 42

You might also like