data representation
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