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

Data Representation

This document discusses data representation in computing systems. It covers floating point number representation using a binary point to represent fractional values. It also discusses fixed point number representation using an implicitly fixed binary point. Finally, it discusses basic data formats, word lengths, and storage order conventions like big-endian and little-endian for ordering bytes in multi-byte data types.

Uploaded by

Jahid Fahim.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Data Representation

This document discusses data representation in computing systems. It covers floating point number representation using a binary point to represent fractional values. It also discusses fixed point number representation using an implicitly fixed binary point. Finally, it discusses basic data formats, word lengths, and storage order conventions like big-endian and little-endian for ordering bytes in multi-byte data types.

Uploaded by

Jahid Fahim.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

ICT 409

13 Dec 2020

Data Representation

Md. Sharif Hossen, Assistant Professor, Dept. of ICT, Comilla University


Outline
Floating Point Number Representation
Shifting Operation
Fixed Point Number Representation
Data Representation
 Basic Formats
 Word lengths
 Storage Order
 Big-endian
 Little-endian

2
Floating Point Number Representation
Consider a binary number 1101012 which
represents the value:
1 * 25 + 1 * 24 + 0 * 23 + 1 * 22 + 0* 21 + 1 * 20
= 32 + 16 + 4 + 1
= 5310
Divide the number 53 by 2, the result would be
26.5.

How do we represent it if we only had integer


representations?

3
Floating Point Number Representation
Consider a binary number 1101012 which
represents the value:
1 * 25 + 1 * 24 + 0 * 23 + 1 * 22 + 0* 21 + 1 * 20
= 32 + 16 + 4 + 1
= 5310
Divide the number 53 by 2, the result would be
26.5.
How do we represent it if we only had integer
representations?
The key to represent fractional numbers, like
26.5 above, is the concept of binary point. A binary
point is like the decimal point in a decimal system. It
acts as a divider between the integer and the
fractional part of a number.
4
Floating Point Number Representation
In a decimal system, a decimal point denotes the
position in a numeral that the coefficient should
multiply by 100 = 1. For example, in the numeral
26.5, the coefficient 6 has a weight of 100 = 1.

2 * 101 + 6 * 100 + 5 * 10-1 = 26.5

As in the decimal system, a binary point represents


the coefficient of the term 20 = 1. All digits (or bits)
to the left of the binary point carries a weight of
20, 21, 22, and so on. Digits (or bits) on the right of
binary point carries a weight of 2-1, 2-2, 2-3, and so
on. So 11010.12 represents the value
1 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 0* 20 + 1 * 2-1
= 16 + 8 + 2 + 0.5 = 26.5
5
Shifting Operation
Used Instead of Binary Point
In the case of 5310, there is "no" binary point.
Alternatively, we can say the binary point is located
at the far right, at position 0. (Think in decimal, 53
and 53.0 represents the same number.)
Binary
25 24 23 22 21 20 2-1 2-2 2-3
Point
1 1 0 1 0 1 . 0 0 0

In the case of 26.510, binary point is located one


position to the left of 5310. Shifting an integer to
the right by 1 bit position is equivalent to
dividing the number by 2.
Binary
25 24 23 22 21 20 2-1 2-2 2-3
Point
0 1 1 0 1 0 . 1 0 0
6
Fixed Point Number Representation
To represent a real number in computers (or any
hardware in general), we can define a fixed point
number type simply by implicitly fixing the binary
point to be at some position of a numeral. W we
need are two parameters:
• width (w) of the number representation, and
• binary point position (b) within the number
Hence, the notation is fixed<w,b>
For example, fixed<8,3> denotes a 8-bit fixed
point number, of which 3 right most bits are
fractional. Therefore, the bit pattern:
0 0 0 1 0 1 1 0
represents a real number:
00010.1102 = 1 * 21 + 1 * 2-1 + 1 * 2-2
= 2 + 0.5 + 0.25 = 2.75
7
Fixed Point Number Representation
0 0 0 1 0 1 1 0

A bit pattern can represent anything. Therefore the


same bit pattern, if we "cast" it to another type,
such as a fixed<8,5> type, will represents the
number:
000.101102 = 1 * 2-1 + 1 * 2-3 + 1 * 2-4
= 0.5 + 0.125 + 0.0625 = 0.6875

If we treat this bit patter as integer, it represents


the number:
000101102 = 1 * 24 + 1 * 22 + 1 * 21
= 16 + 4 + 2 = 22

H.T. Write a program in C++ to represent fixed point number.

8
Data Representation
Basic Formats
Figure 3.15 shows the fundamental division of
information into instructions (operation or control
words) and data (operands).

Data can be further subdivided into numerical and


nonnumerical. Two main number formats have evolved:
fixed-point and floating-point.

The binary fixed-point format takes the form


bAbBbC…bK, where each bi is 0 or 1 and a binary point is
present in some fixed but implicit position.

A floating-point number, on the other hand, consists of a


pair of fixed-point numbers M, E, which denote the
number M x BE, where B is a predetermined base.
9
Data Representation
Nonnumerical data usually take the form of variable-
length character strings encoded in one of several
standard codes, such as ASCII code.

Non-numerical data represents characteristics such


as a person’s gender, marital status, hometown,
ethnicity or the types of movies people like. An
example is non-numerical data representing the
colors of flowers in a yard: yellow, blue, white, red,
etc.

10
Data Representation
Information

Instruction Data

Numbers Nonumerical Data

Fixed Point

Binary

Decimal

Floating Point

Binary

Decimal

Figure 3.15 The basic information types


11
Data Representation
Word Length
Information is represented in a digital computer by
means of binary words, where a word is a unit of
information of some fixed length n. An n-bit word
allows up to 2n different items to be represented. For
example, with n = 4, we can encode the 10 decimal digits
as follows:
0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100

5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001

Number of bits AC can store at a time. Word size is


typically a multiple of 8, common CPU word sizes being 8,
16, 32, and 64 bits.

12
Data Representation
Storage Order
A small but important aspect of data representaion is the
way in which the bits of a word are indexed as shown in
Fig.1, where the right-most bit is assigned the index 0
and the bits are labeled in increasing order from right to
left.
Byte 3 Byte 2 Byte 1 Byte 0

31………………….23………………..15………………….7………………….0
MSB LSB
Fig 1. Indexing convention for the bits and bytes of a word.

The advantage of this convention is that when the word is


interpreted as an unsigned binary integer, the low order
indexes correspond to the numerically less significant bits
and the high-order indexes more significant bits.
13
Data Representation
Suppose a sequence W0, W1,…,Wm of m 4-byte number
words is to be stored. Suppose further that Wi as Bi,3,
Bi,2, Bi,1, Bi,0. Hence the entire sequence can be written
as
W0,W1,…Wm = B0,3,B0,2,B0,1,B0,0,B1,3,B1,2,B1,1,B1,0,….., Bm,3,Bm,2,Bm,1,Bm,0

This storage sequence is called big-endian and shown in


Fig 3.18 a. It is so named because the most significant
byte Bi,3 of word Wi is assigned the lowest address and
the least significant byte Bi,0 is assigned the highest
address. In other words, the big-endian scheme
assigns the highest address to byte 0.

14
Data Representation
The alternative byte-storage scheme called little-endian
assigns the lowest address to byte 0. This corresponds
to
W0,W1,…Wm=B0,0,B0,1,B0,2,B0,3,B1,0,B1,1,B1,2,B1,3,….., Bm,0,Bm,1,Bm,2,Bm,3

and is illustrated by Fig. 3.18 b.

For example, the Motorola 680X0 uses the big-endian


method, whereas the Intel 80X86 series is little-endian.

15
Data Representation
Higher

….
….
address
...00C B3,3 ...00C B3,0
...00B B2,0 ...00B B2,3
...00A B2,1 ...00A B2,2
...02 ...02
...009 B2,2 ...009 B2,1
...008 B2,3 ...008 B2,0
….


...003 B0,0 ...003 B0,3
...002 B0,1 ...002 B0,2
...00 ...00
...001 B0,2 ...001 B0,1
Lower B0,0
...000 B0,3 address
...000

Byte Word Byte Word


address address address address
(a) Big-endian (b) Little-endian
Fig. 3.18 Basic byte storage methods

16

You might also like