Data Representation
Data Representation
1
Data Representation
• Binary: The computer numbering system.
1 binary digit allows 2n = 2 codes (0,1)
2 binary digit allows 2n = 4 codes (00,01,10,11)
3 binary digit allows 2n = 8 codes (000,…..111)
…………………………………………………
7 binary digit allows 2n = 128 codes (0000000,…..1111111)
8 binary digit allows 2n = 256 codes (00000000,…..11111111)
2
Data Representation
• Bit: 0 (Off) or 1 (On).
3
Data Representation
• Integer:
• Floating Point:
• Character:
– ASCII
– EBCDIC
– Unicode
• Boolean:
4
Integers
Decimal Binary
1 00000001
4 00000100
9 00001001
-1 11111111
-4 11111100
-9 11110111
5
Positive Number Representation
Using Integers: The simplest numbers to consider are the integers. The
positive integer numbers are called unsigned. And the integer numbers that
can also be negative are called signed.
13 = 1 × 101 + 3 × 100
6
Positive Number Representation
Conversion between Decimal and Binary systems:
1. For an example the binary number 1101 represents the value
V = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20
V = 13
Hence, (1101)2 = (13)10
9
Floating Point
10
Floating Point Representation
• Floating point numbers can be stored into 32-bits, by dividing the bits
into three parts:
the sign, the exponent, and the mantissa.
• the plus/minus sign is represented by one bit, the highest-weighted bit
(furthest to the left)
• the exponent is encoded using 8 bits immediately after the
sign
• the mantissa (the bits after the decimal point) with the
remaining 23 bits
11
Floating Point Representation
• The first (leftmost) field of our floating point
representation will be the sign bit:
– 0 for a positive number,
– 1 for a negative number.
12
Storing the Binary Form
How do we store a radix point?
- All we have are zeros and ones…
Make sure that the radix point is ALWAYS in the same
position within the number.
Use the IEEE 32-bit standard
the leftmost digit must be a 1
Solution is Normalization
Every binary number, except the one corresponding to the
number zero, can be normalized by choosing the exponent
so that the radix point falls to the right of the leftmost 1 bit.
2-10
28
Answers
2-10
exponent -10 8-bit
bias +127 value
117 01110101
28
exponent 8 8-bit
bias +127 value
135 10000111
IEEE Floating Point Representation
• The mantissa is the set of 0’s and 1’s to the right of the
radix point of the normalized (when the digit to the left
of the radix point is 1) binary number.
Ex: 1.00101 X 23
(The mantissa is 00101)
Step 1.
Compute the binary equivalent of the whole part and
the fractional part. (i.e. convert 40 and .15625 to their
binary equivalents)
Decimal Floating Point to
IEEE standard Conversion
40 .15625
Result: Result:
101000 .00101
Decimal Floating Point to
IEEE standard Conversion
101000.00101 = 1.0100000101 x 25
Decimal Floating Point to
IEEE standard Conversion
127 + 5 = 132
13210 = 100001002
Decimal Floating Point to
IEEE standard Conversion
0 10000100 01000001010000000000000
Decimal Floating Point to
IEEE standard Conversion
Decimal Floating Point to
IEEE standard Conversion
Step 2.
Normalize the number by moving the
decimal point to the right of the leftmost
one.
-11000.11 = -1.100011 x 24
26
Decimal Floating Point to
IEEE standard Conversion
(EBCDIC).
• UNICODE
28