0% found this document useful (0 votes)
18 views79 pages

Ch-2-Data Representation

Uploaded by

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

Ch-2-Data Representation

Uploaded by

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

Chapter 2

DATA REPRESENTATION

1
Introduction
• A bit is the most basic unit of information in a
computer.
– It is a state of “on” or “off” in a digital circuit.
– Sometimes these states are “high” or “low” voltage
instead of “on” or “off..”
• A byte is a group of eight bits.
– A byte is the smallest possible addressable (can be
found via its location) unit of computer storage.
• A word is a contiguous group of bytes.
– Words can be any number of bits (16, 32, 64 bits are
common).

2
Numeric data representation
and
Number bases

3
Number Systems
• Every computer stores numbers, letters, and
other special characters in a coded form.
• Before going into the details of these codes, it
is essential to have a basic understanding of
the number system.
• Number systems are basically of two types:
non-positional and positional

4
Non-Positional Number Systems
• In this system, we have symbols such as I for 1,
II for 2, III for 3, IIII for 4 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 number system, positional number
systems were developed as the centuries
passed.
5
Positional Number Systems
• In positional number system there are only a
few symbols called digits, and these symbols
represent different values depending on the
position they occupy in the number.

6
The value of each digit in such a number is
determined by three considerations:

• The digit itself.


• The position of the digit in the number, and
• The base of the number system (where base
is determined as the total number of digits
available in the number system)

7
Here are 4 important positional
number systems
• Decimal Number System
• Binary Number system
• Hexadecimal Number System
• Octal Number System

8
Decimal number system
• The number system that we use in our day-to-day life
is called the Decimal number system. Decimal
number system is a base 10 system which means
there are 10 digits starting from 0 to 9 to represent
any quantity.
– Value of the digits depends on the position they hold.
– For eg: the number 1024
Total Value: 4*100+2*101+0*102+1*103 = 1024
• Thus any number can be represented by using the
available digits and arranging them in various
positions.
9
Binary Number System
• The Binary Number system is a base 2 system
with only two digits 0 and 1.
• Each position in a binary number represents a
power of the base (2).

Bit value : 1 1 1 1 1 1 1 1
Position value :128 64 32 16 8 4 2 1
Bit number :7 6 5 4 3 2 1 0

10
Octal Number System
• Octal Number System is a base 8 system. So in
this system there are only eight symbols or
digits: 0,1,2,3,4,5,6,7.
• Each position in octal number represents a
power of the base 8.
• Since there are only 8 digits in the octal
number system, 3 bits are sufficient to
represent any octal number in binary

11
Hexadecimal Number System
• Hexadecimal number system is a base 16
system with 16 digits namely
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F;
• Where A represents 10 in decimal,
• B represents 11 in decimal ,
• C represents 12 in decimal ,
• D represents 13 in decimal,
• E represents 14 in decimal and
• F represents 15 in decimal.
12
Converting From One Number
System to Another

13
Converting To Decimal from another
Base
• Step 1: determine the positional value of each
digit.
• Step 2: Multiply the positional value by the
digits in the corresponding columns.
• Step 3: Sum the products obtained in step 2.
The total is the equivalent value in decimal.

14
Binary to Decimal
Eg: 11002 =? 10
Positional value Step 2
Digit (step 1)

0 (right most 20 0*20


digit)
0 21 0*21

1 22 1*22

1 23 1*23

Total (Step 3) 4+8=12

Therefore 11002 =1210

15
Octal to Decimal

Eg: 47068=? 10

=6*80+0*81+7*82+4*83
=250210

16
Hexadecimal to Decimal

1AC16 =? 10

=C*160+A*161+1*162
=12*1+10*16+256
=42810

17
Converting From Decimal to a New Base
• Step 1: Divide the decimal number to be converted
by the value of the new base.
• Step 2: Record the remainder from step 1 as the
rightmost digit (least significant digit) of the new
base number.
• Step 3: Divide the quotient of the previous divide by
the new base.
• Step 4: Record the remainder from step 3 as the next
digit (to the left) of the new base number.
• Repeat steps 3 and 4 recording remainders from right
to left, until the quotient becomes zero in step 3.
• Note that the last remainder thus obtained will be
the most significant digit (MSD) of the new base
number. 18
Decimal To Binary
• 2510 =? 2

2∟25
2∟12- 1
2∟6- 0
2∟3- 0
1- 1
= 110012
19
Decimal To Octal

• 95210 =? 8

8∟952
8∟119- 0
8∟14- 7
1- 6
=16708
20
Decimal To Hexadecimal

• 42810 =? 16

16∟428
16∟26- 12
1- 10

=1 10 12
=1 A C 16 21
Converting from a Base Other than 10(Decimal)
to Base Other than 10 (Decimal)

• Step 1: Convert the original number to a


decimal number (base 10)
• Step 2: Convert the decimal number so
obtained to the new base.

22
• Eg: 3456 =? 4
First, Convert 3456 into its equivalent decimal.

=5*60+4*61+3*62
=5+24+108
=13710
• Now, convert 137 10 =? 4
4∟137
4∟34- 1
4∟8- 2
2- 0 23
Shortcut Method for Binary to Octal
Conversion

• Step 1: Divide the binary digits into groups of


three (starting from the right)
• Step 2: Convert each group of 3 binary digits
into one octal digit.
• 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.

24
• 1011102 =?8

Step 1: 101 110


Step 2: 510 610
58 68
1011102 =568

25
Shortcut Method For Octal To Binary
Conversion
• Step 1: Convert each octal digit to a 3 digit
binary number.
(Here octal digits are considered as decimals.)
• Step 2: Combine all the resulting binary
groups into a single binary number.

26
• Eg: 568 = ?2

58 = 510 = 1012
68 = 610 = 1102

568 = 1011102

27
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 digits to one
hexadecimal digit.
• Hexa decimal digits 0 to 9 are equal to decimal digits
0 to 9, and hexa decimal digits A to F are equal to
decimal 10 to 15.
• Hence the binary to decimal conversion procedure
can be used, but the decimal values 10 to 15 must be
represented as hexa decimal A to F

28
Shortcut Method for Hexadecimal to
Binary Conversion

• Step 1: Convert the decimal equivalent of


each hexa digit to a 4 digit binary number.
• Step 2: Combine all the resulting binary
groups into a single binary number.

29
Fractional Numbers
• In binary, octal and hexa decimal number
system, fractional numbers are formed in the
same general way as in decimal number
system.
• For eg: 68.53= (6*101) + (8*100) + (5*10-1) +
(3*10-2)
• Similar representation is given to other
number systems also.

30
Conversion of Binary Fraction into
Equivalent Decimal

• 110.1012
= 1*22 + 1*21 + 0*20 + 1*2-1 + 0*2-2 +
1*2-3
= 4+2+0+0.5+0+0.125
= 6.62510

31
Conversion of Decimal Fraction into Equivalent
Binary
6.62510 = ?

we know 610=1102

and 0.62510 = ? 10

0.625 * 2 = 1. 25
0.25 * 2 = 0. 50
0.50 * 2 = 1. 00
Hence 0.625 = .1012
Therefore 6.62510 = 110.1012

32
• Here, just go on multiplying the decimal part
with 2 until you get a 0 in the decimal part.
• note that for some numbers you won’t get a 0
in the decimal part. In that case, stop by third
or fourth step.
• for octal conversion multiply by 8 and for hexa
decimal conversion multiply by 16.

33
Conversion of Octal Fraction into
Equivalent Decimal.

• 127.548 = ?10

= 1*82 + 2*81 + 7*80 + 5*8-1 + 4 *8 -2


= 64+16+7+.625+.0625
= 87.687510

34
Conversion of Decimal Fraction into
Equivalent Octal.
• 87.687510 = ? 8
8∟87
8∟10- 7 = 1278
1- 2

Now,
0.6875 * 8 = 5.5
0.5 * 8 = 4.0 = .548
Hence,
87.687510 = 127.548
35
Conversion of Hexa-Decimal Fraction into
Equivalent Decimal.

• 2B.C416 = ?10

= 2*161 + B*160 + C*16-1 + 4* 16-2


= 43+.75+.015625
= 43.76562510

36
Fixed- and Floating-point
systems

37
• In representing integer in computers with binary
numbers, binary point is fixed and the operation
is known as fixed point arithmetic.
• To represent numbers in such a way that binary
point is variable and is automatically adjusted in
computation, floating point representation is
used.
• Since the binary point is said to float (move)
numbers are known as floating point numbers.
• Floating point representation is similar to
scientific notation in decimal number system.
38
• A floating point number ‘a’ can be represented as
a = (sign) * m * be
Where sign can be 0 for positive and 1 for
negative.
m  significand or mantissa .This shows the digits
that define the number’s magnitude.
e exponent or characteristic or scale to indicate
the position of the binary point.
b base or radix of the numeration.

Eg: 121.5 = 1.125 *102


101010.111= 1.01010 * 25
39
Binary floating-point numbers in IEEE
standard as follows:
Sign Bit Exponent Mantissa

• where the most significant bit is the sign bit,


exponent is the biased exponent, and mantissa
is the significant minus the most significant bit.

40
Normalized form in binary floating
point number
• If the leading digit of mantissa is non zero
then the number is said to be normalized.
• When a number is normalized, its most bit
significant bit is 1.
• In the IEEE Single and double precision
formats, that bit is called the “hidden” bit or
“implicit” bit.

41
Exponent biasing
• The exponent is biased by (2e-1 ) - 1.
• In the case of single precision representation, e = 8
i.e. = ( 28-1 ) – 1
= 127
• In the case of a double precision representation,
e =11
i.e. = ( 211-1 ) – 1
= 1023
• In the case of single precision, the biased exponent = real exponent + 127
• In the case of a double precision, the biased exponent = real exponent + 1023

42
IEEE 754 standard
• Single precision and double precision
representation using binary.

43
Single precision representation (32 bits)
Sign Bit(1 bit) Exponent(8-bits) Mantissa(23-bits)

s = +1 (positive numbers) when the sign bit is 0


s = −1 (negative numbers) when the sign bit is 1

e = Exp + 127 (in other words the exponent is stored with


127 added to it, also called "biased with 127")

m = Fraction in binary (that is, the significand is the binary


number 1 followed by the radix point followed by the
binary bits of Fraction).
44
1. Encode the decimal number −118.625 using the IEEE system.
• First we need to get the sign, the exponent and the fraction.
Because it is a negative number, the sign is "1".
• Now, we write the number (without the sign) using binary
notation. The result is 1110110.101.
• Next, let's move the radix point left, leaving only a 1 at its left.
That is value of the number is in the range 1<m<2. This is known
as normalization.
• 1110110.101 = 1.110110101 × 26. This is a normalized floating
point number. Since the first digit is now always going to be 1,
there is no need to encode this digit. The mantissa only includes
the digits after the point and the leading 1 is kept as hidden bit.
The mantissa is the part at the right of the radix point, filled
with 0 on the right until we get all 23 bits. That is
11011010100000000000000.
45
46
47
Double-precision binary floating-point number-
stored in a 64-bit word:

(1 bit) (11-bits) (52-bits)


Sign Bit Exponent Mantissa

•Double precision is essentially the same as single


precision, except that the fields are wider:
•The mantissa is much larger (52-bits), while the
exponent is only slightly larger (11 bits).

48
Signed and Two’s-complement
Representations

49
Sign and Magnitude Method
– Left most bit of the binary number is used to
represent whether the number is positive (+) or
negative (-).
– Left most is the Most Significant Bit (MSB) and is
know as sign bit in this method.
– If the sign bit is 1 the number is negative and if it
is 0 the number is positive.
– Sign bit is the MSB, with magnitude being a binary
number using the remaining bits.

50
Signed Integer Representation
In 8-bit signed magnitude,
• Positive 3 is: 00000011
• Negative 3 is: 10000011
• Computers perform arithmetic operations on
signed magnitude numbers the same way as
humans do pencil and paper arithmetic.
– Humans ignore the signs of the operands while
doing a calculation, applying the appropriate sign
at the end.

51
Signed Integer Representation
• Binary addition is as easy as it gets. You
need to know only four rules:
0 + 0 = 0 0 + 1 = 1
1 + 0 = 1 1 + 1 = 10
• The simplicity of this system makes it
possible for digital circuits to carry out
arithmetic operations.

Let’s see how the addition rules work with signed


magnitude numbers . . .
52
Signed Integer Representation
• Example:
• Using signed magnitude binary
arithmetic, find the sum of 75 and 46.
• Convert 75 and 46 to binary, and
arrange as a sum. Separate the
(positive) sign bits from the
magnitude bits.
• As in decimal arithmetic, find the
sum starting with the rightmost bit
and work left.

• In the second bit, we have a carry,


so we note it above the third bit.

53
Signed Integer Representation
• Signed magnitude representation 4-bit
Binary Decimal
is easy for people to understand, 1000 -8
but needs complicated computer 1001 -7
hardware. 1010
1011
-6
-5
• Another disadvantage: it allows 1100
1101
-4
-3
two different representations for 1110 -2
zero: positive zero and negative 1111 -1
0000 0
zero. 0001 1
0010 2
• So computers systems employ 0011 3
complement systems for numeric 0100 4
value representation. 0101 5
0110 6
0111 7
54
One’s Complement Method

• All the 1 bits is changed to 0 and all the 0 bit


is changed to 1 to get the complement of a
number.
• One’s Complement of the number is treated
as the negative of that number.

55
Two’s Complement Method

• Two’s complement of a number is one’s


complement of a number + 1.
• Two’s complement of a number is treated as
the negative representation of the number.
• 2’s complement method is used in modern
computing.

56
Representation of Non-numeric
data
(Character codes, Graphical data)

57
• Computer handles different types of data
namely Numeric data, alphanumeric data,
alphabetic data etc.
• All data and programs that go into the
computer are represented in terms of binary
numbers.

58
Alphanumeric Data
• Three standards for representing letters
(alpha) and numbers
– ASCII – American Standard Code for Information
Interchange
– EBCDIC – Extended Binary-Coded Decimal
Interchange Code (not used anymore, used to be
used in IBM mainframes)
– Unicode
BCD (Binary Coded Decimal)
• BCD is one of the early memory codes. In BCD each
digit of a decimal number is converted into its
binary equivalent rather than converting the entire
decimal value into binary form. And each decimal
digit uses 4 bits for this conversion.
• Eg: 4210 is not equal to 1010102 in BCD
4210 is equal to 0100 00102 in BCD
(Here 410 = 0100 and 210 = 0010)

60
• 910 = 10012 in BCD

• 110 = 00012 in BCD

• 1010 = 0001 00002 in BCD

• 1510 = 0001 01012 in BCD

61
• Since 4 bits is insufficient to represent characters,
6 bits representation was introduced in BCD
coding.
• 6 bits were enough to represent 10 decimal
digits, 26 alphabetic letters and 28 other special
characters.
• Also using 6 bits we can represent 26(=64)
different characters.
• 6 bit BCD code can be easily divided into 3 bit
groups and each group can be represented by 1
octal digit. Thus octal number is used as shortcut
notation in BCD coding.
62
BCD Coding Scheme for All Numeric and Alphabetic
Characters

63
Codes and Characters
• The problem:
– Representing text strings, such as
“Hello, world”, in a computer
• Each character is coded as a byte ( = 8 bits)
• Most common coding system is ASCII
• ASCII = American National Standard Code for
Information Interchange
• Defined in ANSI document X3.4-1977
ASCII Features
• 7-bit code
• 8th bit is unused (or used for a parity bit)
• 27 = 128 codes
• Two general types of codes:
– 95 are “Graphic” codes (displayable on a console)
– 33 are “Control” codes (control features of the
console or communications channel)
Most significant bit

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

Least significant bit


000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

i.e. ‘a’ = 11000012 = 9710 = 6116


000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

95 Graphic codes
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

33 Control codes
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

Alphabetic codes
“Hello, world” Example

Binary Hexadecimal Decimal


H = 01001000 = 48 = 72
e = 01100101 = 65 = 101
l = 01101100 = 6C = 108
l = 01101100 = 6C = 108
o = 01101111 = 6F = 111
, = 00101100 = 2C = 44
= 00100000 = 20 = 32
w = 01110111 = 77 = 119
o = 01101111 = 6F = 111
r = 01110010 = 72 = 114
l = 01101100 = 6C = 108
d = 01100100 = 64 = 100

Note: 12 characters – requires 12 bytes


Each character requires 1 byte
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

Numeric codes
“4+15” Example

Binary Hexadecimal Decimal


4 = 00110100 = 34 = 52
+ = 00101011 = 2B = 43
l = 00110001 = 31 = 49
5 = 00110101 = 35 = 53

“4+15” is represented as
“00110100 00101011 00110001 00110101”

or “34162B1631163516”
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

Punctuation, etc.
Representation of
Records and Arrays

75
An array is a sequenced collection of elements, normally of
the same data type, although some programming languages
accept arrays in which elements are of different types. We
can refer to the elements in the array as the first element,
the second element and so forth, until we get to the last
element.
Records
• A record is a collection of related elements,
possibly of different types, having a single
name. Each element in a record is called a
field. A field is the smallest element of named
data that has meaning. A field has a type and
exists in memory. Fields can be assigned
values, which in turn can be accessed for
selection or manipulation. A field differs from
a variable primarily in that it is part of a
record.
77
Comparison of Records and Arrays
• An array defines a combination of elements,
while a record defines the identifiable parts
of an element.
• For example, an array can define a class of
students (40 students), but a record defines
different attributes of a student, such as id,
name or grade.

78
`

END

79

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy