0% found this document useful (0 votes)
4 views

Chapter 1 Data Representation

Computer science

Uploaded by

sajid ali
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Chapter 1 Data Representation

Computer science

Uploaded by

sajid ali
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

CHAPTER 1

DATA REPRESENTATION
DATA AND INFORMATION

• Data is the raw facts and figures and can be in the


form of numbers, symbols or alphanumeric
characters.
• Data is the raw format before processing.
• Processed data is called information
STUDENT INFO

Std_ID Std_name Class Section House


CC001 Abrar 9 C Generosity
BB210 Muntaha 10 G Courage
AA123 Zayan 9 G Service
BB125 Arham 10 S Courage
AA149 Karim 11 K Generosity
CC147 Samin 9 M Service
Data

Analog Data Digital Data


• This is the smooth stream of • That consists of individually
data that our senses process recognizable binary digits 0
on a daily basis. and 1
• Computers cannot process Example : text, image, sound,
analogue data video
NUMBER SYSTEMS

There are following three number systems:


i) Denary (Decimal) number system - Base 10 (0-9)
ii) Binary number system Binary - Base 2 (1 and 0)
iii) Hexadecimal number system - Base 16
(1-F)
DENARY NUMBER SYSTEM

Denary Numbers
• In our daily lives we use denary 0 10 20 31 41 51
1 11 21 32 42 52
number system.
2 12 23 33 43 53
• This system uses the digits 0-9 . 3 13 24 34 44 54
4 14 25 35 45 55
• It is called base 10 number
5 15 26 36 46 …..
system. that means the units it 6 16 27 37 47
uses increases by the power of 10. 7 17 28 38 48
8 18 29 39 49
9 19 30 40 50
245

• increased by power of 10
increased by power of 10

Hundreds Tens Ones


2 + 4 + 5
2 Hundreds+ 4 Tens + 5 Ones = 245
DENARY (DECIMAL) NUMBER SYSTEM :

• The weights of digits according to their positions are given below:

Position 5th 4th 3rd 2nd 1st

Weight 104 103 102 101 100

10000 100 100 10 1


7 6 8 5 4

76854 can be expressed as:


= 7 x 10000 + 6 x 1000 + 8 x 100 + 5 x 10 + 4 x 1
= 70000 + 6000 + 800 + 50 + 4
= 76854
BINARY NUMBER SYSTEM

• “The number system which is based on two


characters 0 and 1 is called binary system.”
• Computer circuit represents data in a pattern
of ON and OFF states of electric current.
• The state ON is represented by ‘1’ and OFF is
represented by ‘0’.
USES OF BINARY SYSTEM

Binary system is used for internal


working of electronic computers.
To process data in logic gates/transistors.
To store data in registers.
To process data on the computer.
Binary Number System

The weights of digits according to their positions are


given below:
Positio 9th 7th 6th 5th 4th 3rd 2nd 1st
n
Weight 27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

• With the help of above chart we can derive a sequence of number, that sequence is
known as Binary Notation.
CONVERTING FROM BINARY TO DENARY

• If we take the binary number 1100 we can calculate its value as a


denary number.
• Units begin at right hand side and increase by the power of 2 as we
move left.
8 4 2 1
• 1 indicates Binary
we use that
1 unit
1 ,0 0
indicates
0 we do not.

Denar 8 + 4 + 0
y + 0

So the binary number 1100 as a denary number is 12.


BINARY TO DENARY

• To convert 8 bit binary numbers into denary we need to add together all
the binary units that are marked as required by the digit 1.
• If we take the binary number 10010100 we can draw a table to see what
units are7 needed:
2 2 6
2 5
2 4
2
3 2
2 2
1
2
0

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

Denary : 128+16+4=148
CONVERTING FROM DENARY TO BINARY

• Method 1

The denary number 142 is made up of 128 + 8 + 4 + 2 in each stage,


subtract the largest possible power of 2 and keep doing this until the value
0 is reached. This will give us the following 8-bit binary number:

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1
1 0 0 0 1 1 1 0
CONVERTING FROM DENARY TO BINARY

Method 2 Divid Quotie Remainde


 This method involves successive division by 2. e by nt r
 Start with the denary number, 142, and
divide it by 2. Read the
remainde
 Write the result of the division including the r from
remainder (even if it is 0) under the 142 (that bottom
is, 142 ÷ 2 = 71 remainder 0); then divide to top
again by 2 (that is, 71 ÷ 2 = 35 remainder 1)
 keep dividing until the result is zero. 14 2 71 0
 Finally write down all the remainders in 2
reverse order: 71 2 35 1
35 2 17 1
10001110
17 2 8 1

This method is helpful


4 2
for
2
beyond
0
8 8 2 4 0
HEXADECIMAL NUMBER SYSTEM

• Hexadecimal - a system of numbers with a


base of 16.
• Each unit used increases by the power of 16
• Computers do not actually process
hexadecimal ,They convert it into binary before
processing it.
Why hexadecimal is used :

1. Easily understandable: Programmers work with hexadecimal as


it is easier for humans to read than binary.
2. Easier to debug :Programs that are written in hexadecimal are
easier to debug than those written in binary.
3. Takes less space on the screen :It is a much shorter way of
representing a byte of data, as reading and understanding lots of
binary 1s and 0s can be difficult.
WHERE HEXADECIMAL IS USED

1. Used in colour codes : Hexadecimal (hex) is used as a notation for colour in HTML.
2. Used in error codes: Standard Windows error message codes are given in
hexadecimal notation, for example error code 404 (meaning 'File not found') is a
hexadecimal notation.
3. Used in IPv6 address :128-bit addresses that take the form of eight groups of hex
digits; for example,
A8FB:7A88:FFF0:0FFF:3D21:2085:66FB:F0FA
4. Used in MAC addresses : Media Access Control (MAC) addresses are 12-digit
hexadecimal numbers that uniquely identify each different device in a network. An
example of MAC address would be 00-1B-63-84-45-E6.
HEXADECIMAL NUMBER SYSTEM

• Hexadecimal uses 16 symbols, the numbers 0-9 and the letters A-F.
• The notation for each denary number between 0 and 15 is shown in Table .

Denary 0 1 2 3 4 5 6 7 8 9 10 11 12 1 14 1
3 5
Hexadeci 0 1 2 3 4 5 6 7 8 9 A B C D E F
mal
CONVERTING FROM BINARY TO HEXADECIMAL

• To convert binary into hexadecimal we take each


8 4 2 1 8 4 2 1 8 4 2 1
binary number and separate it into 4 digit nibbles.
1 0 1 1 1 1 0 0 1 0 0 1
• lf we take the binary number 1011 1100 1001 we
would split it into three 4 digit nibbles,
8+2+1 8+4
1011,1100 and 1001. 8+1
• We can then convert each nibble into a hexadecimal
=11 =12
=9
symbol.
Hexadecimal
B notation
C
• To do this we use the first four binary places 1,2,4 9
of 101111001001 is
and 8 to calculate each hexadecimal symbol
BC9
CONVERTING FROM HEXADECIMAL TO BINARY

• To convert hexadecimal notation back into binary we reverse the process.


• We take the hexadecimal notation BC9 and convert the denary value of each
hexadecimal unit into a 4-bit binary number.
• We then join the binary numbers together:
• Hexadecimal B C 9
11 12 9

8 4 2 1 8 4 2 1 8 4 2 1
1 0 1 1 1 1 0 0 1 0 0 1

Binary notation of BC9 is


101111001001
CONVERTING FROM HEXADECIMAL TO
DENARY
• To convert hexadecimal numbers into denary involves
the value headings of each hexadecimal
409 256 16 1 digit :
6

• Take each of the hexadecimal digits and multiply it by the heading values.
• Add all the resultant totals together to give the denary number.
• Remember that the hex digits A → F need to be first converted to the
values 10 → 15 before carrying out the multiplication.
CONVERTING FROM HEXADECIMAL TO
DENARY
• 1AB
1 A B
1 10 11

256 16 1
1 10 11
1x 256 16 x10 1 x11
256 + 160 + 11
= 427

Hexadecimal notation for Denary number 427 is


1AB
CONVERTING FROM DENARY TO HEXADECIMAL

METHOD 1

• 55

161 160

16 1
3x16 =48 and 7x1
55/16 = 3
=7 remainder 7
Hexadecimal 3 7
Denary 48 + 7
48 + 7 = 55
CONVERTING FROM DENARY TO HEXADECIMAL

METHOD 2

Divid Quotien Remainde


• This method involves e by t r Read the
remainder
successive division by from
bottom
16. to top
• Convert 2004 to 7 13 4
Hexadecimal
200 16 125 4
4
125 16 7 13
Hexadecimal
7 of
16 2004
0 10 7is 7D4
Sum Carry
0+0 0 0
ADD TWO POSITIVE 8-BIT 0+1 1 0

BINARY INTEGERS 1+0 1 0


1+1 1 1

•Add 76 and 56 in binary


128 64 32 16 8 4 2 1
•76 = 01001100 Carr 1 1 1 1
y
•62 = 00111110 76 0 1 0 0 1 1 0 0

•(76 + 62 = 138) 62 0 0 1 1 1 1 1 0
Sum 1 0 0 0 1 0 1 0
CONCEPT OF OVERFLOW:

•Overflow error is the result of carrying out a calculation that produces a value too large for
the computer’s allocated word size.

• Example: Add 120 + 145 in binary


(120 + 145 = 265; an 8-bit register can store a maximum value of 255)
.
12 64 32 16 8 4 2 1 •The extra carry in the answer indicates
8 that overflow error has occurred. The
Carr 1 1 1 1 1 1 answer is greater than 255.
y •Overflow error occurs when the value is
120 0 1 1 1 1 0 0 0 greater than the maximum value of the
145 1 0 1 1 0 0 0 1
register
Sum 0 0 1 0 1 0 0 0
Two’s complement (binary numbers)

To represent positive and negative 8-bit binary


integers
• In two’s complement the left-most bit is changed to a
negative value.
• For instance, for an 8-bit number, the value 128 is now
changed to -128, but all the other headings remain the
same.
• This means the new range of possible numbersis:
128 (10000000) to +127 (01111111)
• The left-most bit always determines the sign of the binary
number.
- 64 32 16 8 4 2 1
• A 1-value in the left-most bit indicates a negative number
128
and
• A 0-value in the leftmost bit indicates a positive number
CONVERT -67 TO BINARY

128 64 32 16 8 4 2 1
0 1 0 0 0 0 1 1 • Invert all the
67 =
values is
128 64 32 16 8 4 2 1 called one’s
67 0 1 0 0 0 0 1 1 complement
1’s 1 0 1 1 1 1 0 0
• Add 1 in the
complement
+ 1
inverted
1 0 1 1 1 1 0 1
binary value
-128 64 32 16 8 4 2 1
-67 1 0 1 1 1 1 0 1 -128 + 32 + 16 + 8 + 4 + 1
= = - 67
CONVERT -75 TO BINARY IN TWO’S
COMPLEMENT FORMAT
LOGICAL BINARY SHIFTS
Logical Binary Shifts

Left Shifts :

• Each shift left is


12 64 32 16 8 4 2 1
8 equivalent to
Denary multiplying the
0 0 0 1 0 1 0 1 value: 21 binary number by 2n
12 64 32 16 8 4 2 1 (where n is the
8 number of places
Denary shifted)
0 0 1 0 1 0 1 0 value: 42 • If the leftmost 1 bits
12 64 32 16 8 4 2 1
are lost while
8 shifting to the left,
Denary an error will occur
0 1 0 1 0 1 0 0 value: 84 because the limit of
the maximum
number of left shifts
possible will have
been exceeded
LOGICAL BINARY SHIFTS

RIGHT SHIFTS :
• Each shift right is
12 64 32 16 8 4 2 1
8 equivalent to dividing
Denary value: the binary number by
0 1 1 0 0 1 0 0 100 2n (where n is the
number of places
12 64 32 16 8 4 2 1
shifted)
8
Denary value:
0 0 1 1 0 0 1 0 50
• If the rightmost 1 bits
are lost while shifting
12 64 32 16 8 4 2 1 to the right, an error
8 will occur because the
Denary value: limit of the maximum
0 0 0 1 1 0 0 1 25 number of right shifts
possible will have been
exceeded.

You might also like