data representation

Post on 17-Aug-2015

26 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Department of Civil EngineeringChittagong University of Engineering & Technology

Sanjoy DasLecturer

CE 218Computer Programming Sessional

Data Representation

Data Representation

INTRODUCTION

In our familiar number system we have symbols ( to ) to represent a number.

We call it decimal system or base system.

To process data in a computer, we need to represent them in the registers of the processor.

A register consists of several circuits.

Data Representation

INTRODUCTION

Can we represent 10 symbols using an electric circuit? Obviously no.

We can symbolize an electric circuit into two states such as-

(a) contains current (1)(b) no current(0)

Similarly for a magnetic media such as a disk we may consider two states-

(a) magnetized clockwise (b) magnetized counterclockwise

Data Representation

INTRODUCTION

We may think these two states as two symbols (say one is and the other is ) to represent a number.

Thus we have only two digitsto represent a number in the computer processor, in the memory or in the data storage devices.

Each individual circuit represents a digit and we term it as a bit (it is an abbreviation from binary digit).

Thus, at circuit level, we can represent a number in the computer in binary form.

Data Representation

THE BINARY SYSTEM

Computers work with the binary or base-two system of numbers that uses the two digits and instead of the ten digits of the more familiar decimal or base-ten system.

In the binary system, a number is denoted as-

(1)

Where and are two integer indices.

The binary digits or bits, take the value of or , and the period (.) is the binary point.

Data Representation

THE BINARY SYSTEM

The implied value is equal to-

(2)

Where and are two integer indices.

The decimal digits, take values in the range , and the period (.) is the decimal point.

In the decimal system, the same number is expressed as-

(3)

Data Representation

THE BINARY SYSTEM

The implied value is equal to-

(4)

Which is identical to that computed from the base-two expansion.

Since bits can be represented by the on-o ff positions of electrical switches that are built in the computer’s electrical circuitry, and since bits can be transmitted by positive or negative voltage as a Morse code, the binary system is ideal for developing a computer architecture.

Data Representation

THE BINARY SYSTEMConversion from Decimal to Binary The conversion from a decimal number to a binary

number can be explained by the following example-

(𝟓𝟐𝟎𝟖 )𝟏𝟎=(𝟏𝟎𝟏𝟎𝟎𝟎𝟏𝟎𝟏𝟏𝟎𝟎𝟎 )𝟐

𝟐𝟓𝟐𝟎𝟖𝟐𝟐𝟔𝟎𝟒−𝟎𝟐𝟏𝟑𝟎𝟐−𝟎𝟐𝟔𝟓𝟏−𝟎𝟐𝟑𝟐𝟓−𝟏𝟐𝟏𝟔𝟐−𝟏𝟐𝟖𝟏−𝟎𝟐𝟒𝟎−𝟏𝟐𝟐𝟎−𝟎𝟐𝟏𝟎−𝟎𝟐𝟓−𝟎𝟐𝟐−𝟏𝟏−𝟎

Data Representation

THE BINARY SYSTEMConversion from Decimal to Binary The conversion from a decimal number (non - integer) to

a binary number can be explained by the following example-

(𝟑𝟒𝟓 .28125   )𝟏𝟎=(𝟏𝟎𝟏𝟎𝟏𝟏𝟎𝟎𝟏 .𝟎𝟏𝟎𝟎𝟏 )𝟐

𝟐𝟑𝟒𝟓𝟐𝟏𝟕𝟐−𝟏𝟐𝟖𝟔−𝟎𝟐𝟒𝟑−𝟎𝟐𝟐𝟏−𝟏𝟐𝟏𝟎−𝟏𝟐𝟓−𝟎𝟐𝟐−𝟏

𝟏−𝟎

𝟎 .𝟐𝟖𝟏𝟐𝟓×𝟐=𝟎 .𝟓𝟔𝟐𝟓𝟎 .𝟓𝟔𝟐𝟓𝟎×𝟐=𝟏 .𝟏𝟐𝟓𝟎𝟎 .𝟏𝟐𝟓𝟎𝟎×𝟐=𝟎 .𝟐𝟓𝟎𝟎𝟎 .𝟐𝟓𝟎𝟎𝟎×𝟐=𝟎 .𝟓𝟎𝟎𝟎𝟎 .𝟓𝟎𝟎𝟎𝟎×𝟐=𝟏 .𝟎𝟎𝟎𝟎

Data Representation

THE BINARY SYSTEMConversion from Binary to Decimal The conversion from a binary number to a decimal

number can be explained by the following example-

(𝟏𝟎𝟏𝟎𝟎𝟎𝟏𝟎𝟏𝟏𝟎𝟎𝟎 )𝟐=(𝟓𝟐𝟎𝟖 )𝟏𝟎

𝟎×𝟐𝟎=𝟎𝟎×𝟐𝟏=𝟎𝟎×𝟐𝟐=𝟎𝟏×𝟐𝟑=𝟖𝟏×𝟐𝟒=𝟏𝟔𝟎×𝟐𝟓=𝟎𝟏×𝟐𝟔=𝟔𝟒𝟎×𝟐𝟕=𝟎𝟎×𝟐𝟖=𝟎𝟎×𝟐𝟗=𝟎𝟏×𝟐𝟏𝟎=𝟏𝟎𝟐𝟒𝟎×𝟐𝟏𝟏=𝟎𝟏×𝟐𝟏𝟐=𝟒𝟎𝟗𝟔

𝟓𝟐𝟎𝟖

Data Representation

THE BINARY SYSTEMConversion from Binary to Decimal The conversion from a binary number (non – integer) to a

decimal number can be explained by the following example-

(𝟏𝟎𝟏𝟎𝟏𝟏𝟎𝟎𝟏 .𝟎𝟏𝟎𝟎𝟏 )𝟐= (𝟑𝟒𝟓 .28125   )𝟏𝟎

𝟏×𝟐𝟎=𝟏𝟎×𝟐𝟏=𝟎𝟎×𝟐𝟐=𝟎𝟏×𝟐𝟑=𝟖𝟏×𝟐𝟒=𝟏𝟔𝟎×𝟐𝟓=𝟎𝟏×𝟐𝟔=𝟔𝟒𝟎×𝟐𝟕=𝟎𝟏×𝟐𝟖=𝟐𝟓𝟔

𝟎×𝟐−𝟏=𝟎𝟏×𝟐−𝟐=𝟎 .𝟐𝟓𝟎×𝟐−𝟑=𝟎𝟎×𝟐−𝟒=𝟎

𝟏×𝟐−𝟓=𝟎 .𝟎𝟑𝟏𝟐𝟓

𝟑𝟒𝟓

𝟎 .𝟐𝟖𝟏𝟐𝟓

Data Representation

THE BINARY SYSTEMThe Largest Integer Encoded by Bits

Each individual circuit represents a digit and we term it as a bit (it is an abbreviation from binary digit).

As you all know, the largest number for a given number of digits can be obtained by filling out each position with the largest symbol.

Such as : in decimal, largest number with 3 digits = 999

similarly, in binary, largest number with 3 digits = 111

Data Representation

THE BINARY SYSTEMThe Largest Integer Encoded by Bits

So, the largest integer that can be represented with bits is-

(5)

Where the ones are repeated times. The decimal - number equivalent is-

(6)

Data Representation

THE BINARY SYSTEMThe Largest Integer Encoded by Bits

To demonstrate this equivalence, we recall from our college years-

Where and are two variables and set and .

(7)

Data Representation

THE BINARY SYSTEMThe Largest Integer Encoded by Bits When one bit is available, we can describe only the

integers and , and the largest integer is .

With two bits the maximum is . With three bits the maximum is . With eight bits the maximum is . With thirty-onebits the maximum is

.

Data Representation

THE BINARY SYSTEMSigned Integers To encode a signed integer, we allocate the first bit to

the sign. If the leading bit is , the integer is positive; if the leading

bit is , the integer is negative. The largest signed integer that can be represented with

bits is then-

According to this convention, the integer is stored as the binary string .

Data Representation

THE BINARY SYSTEMSigned IntegersData Representation Scheme for Integers

………………………………………………………..𝟎𝟏𝟐𝟑 𝟑𝟏

Sign Bit

………………………………………………………..

1 1 0 1

𝟎𝟏𝟐𝟑 𝟑𝟏

Sign Bit−𝟓=− (𝟏𝟎𝟏 )𝟐

is stored as the binary string

Data Representation

THE BINARY SYSTEMSigned IntegersData Representation Scheme for Non-Integers (Floating Point Numbers) The floating-point representation allows us to store real

numbers (non-integers) with a broad range of magnitudes, and carry out mathematical operations between numbers with disparate magnitudes.

Data Representation

THE BINARY SYSTEMSigned IntegersData Representation Scheme for Non-Integers (Floating Point Numbers) Consider the binary number-

To develop the floating-point representation, we recast this number into the product-

Note that the binary point has been shifted to the left by nine places, and the resulting number has been multiplied by the binary equivalent of .

The binary string is the mantissa or significand, and is the exponent.

Data Representation

THE BINARY SYSTEMSigned IntegersData Representation Scheme for Non-Integers (Floating Point Numbers) To develop the floating-point representation of an

arbitrary number, we express it in the form-

Where is a real number called the mantissa or significand, and is the integer exponent.

This representation requires one bit for the sign, a set of bytes for the exponent, and another set of bytes for the mantissa.

(9)

Data Representation

THE BINARY SYSTEMSigned IntegersData Representation Scheme for Non-Integers (Floating Point Numbers) In memory, the bits are arranged sequentially in the

following order-

The exponent determines the shift of the binary point in the binary representation of the mantissa.

………………………………………………………..𝟎𝟏𝟐𝟑 𝟑𝟏

Sign Bit

Exponent Mantissa

• For a 32-bit float type, the mantissa is stored in a 23-bit segment and the exponent in an 8-bit segment, leaving 1 bit for the sign of the number. For a 64-bit double type, the mantissa is stored in a 52-bit segment and the exponent in an 11-bit segment.

Data Representation

THE BINARY SYSTEM

top related