Floating Point, BCD, ASCII


Floating Points

floating point

-derived from the fact that there is no fixed number of digits before and after the decimal point.

-that is, the decimal point can float.

 


fixed-point representations

-representations in which the number of digits before and after the decimal point is set.

 

The most popular code for representing real numbers is called the IEEE Floating-Point Standard .



IEE 754 Standard


s
biased exponent
significand

 
s – sign of significand
biased exponent – 8 bits
significand – 23 bits


If we use S for the sign, E for the exponent and M for the mantissa (significand), then the number stored is equivalent to:

(-1)S x M x 2E

The Sign


The sign of a binary floating-point number is represented by a single bit. A 1 bit indicates a negative number, and a 0 bit indicates a positive number.

The Mantissa


It is useful to consider the way decimal floating-point numbers represent their mantissa. Using -3.154 x 105 as an example, the sign is negative, the mantissa is 3.154, and the exponent is 5. The fractional portion of the mantissa is the sum of each digit multiplied by a power of 10:

.154 = 1/10 + 5/100 + 4/1000

A binary floating-point number is similar. For example, in the number +11.1011 x 23, the sign is positive, the mantissa is 11.1011, and the exponent is 3. The fractional portion of the mantissa is the sum of successive powers of 2. In our example, it is expressed as:

.1011 = 1/2 + 0/4 + 1/8 + 1/16

Or, you can calculate this value as 1011 divided by 24. In decimal terms, this is eleven divided by sixteen, or 0.6875. Combined with the left-hand side of 11.1011, the decimal value of the number is 3.6875. Here are additional examples:

Binary Floating-Point
Base 10 Fraction
Base 10 Decimal
11.11
3 3/4
3.75
0.00000000000000000000001
1/8388608
0.00000011920928955078125

The last entry in this table shows the smallest fraction that can be stored in a 23-bit mantissa. The following table shows a few simple examples of binary floating-point numbers alongside their equivalent decimal fractions and decimal values:

Binary
Decimal Fraction
Decimal Value
.1
1/2
.5
.01
1/4
.25
.001
1/8
.125
.0001
1/16
.0625
.00001
1/32
.03125

The Exponent


IEEE Short Real exponents are stored as 8-bit unsigned integers with a bias of 127. Let's use the number 1.101 x 25 as an example. The exponent (5) is added to 127 and the sum (132) is binary 10100010. Here are some examples of exponents, first shown in decimal, then adjusted, and finally in unsigned binary:

Exponent (E)
Adjusted
(E + 127)
Binary
+5
132
10000100
0
127
01111111
-10
117
01110101
+128
255
11111111
-127
0
00000000
-1
126
01111110

The binary exponent is unsigned, and therefore cannot be negative. The largest possible exponent is 128-- when added to 127, it produces 255, the largest unsigned value represented by 8 bits. The approximate range is from 1.0 x 2-127 to 1.0 x 2+128.

Normalizing the Mantissa


Before a floating-point binary number can be stored correctly, its mantissa must be normalized. The process is basically the same as when normalizing a floating-point decimal number. For example, decimal 1234.567 is normalized as 1.234567 x 103 by moving the decimal point so that only one digit appears before the decimal. The exponent expresses the number of positions the decimal point was moved left (positive exponent) or moved right (negative exponent).

Similarly, the floating-point binary value 1101.101 is normalized as 1.101101 x 23 by moving the decimal point 3 positions to the left, and multiplying by 23. Here are some examples of normalizations:

Binary Value
Normalized As
Exponent
1101.101
1.101101
3
.00101
1.01
-3
1.0001
1.0001
0
10000011.0
1.0000011
7

You may have noticed that in a normalized mantissa, the digit 1 always appears to the left of the decimal point. In fact, the leading 1 is omitted from the mantissa in the IEEE storage format because it is redundant.

Creating the IEEE Bit Representation


We can now combine the sign, exponent, and normalized mantissa into the binary IEEE short real representation. Using Figure 1 as a reference, the value 1.101 x 20 is stored as sign = 0 (positive), mantissa = 101, and exponent = 01111111 (the exponent value is added to 127). The "1" to the left of the decimal point is dropped from the mantissa. Here are more examples:

Binary Value
Biased Exponent
Sign, Exponent, Mantissa
-1.11
127
1 01111111 11000000000000000000000
+1101.101
130
0 10000010 10110100000000000000000
-.00101
124
1 01111100 01000000000000000000000
+100111.0
132
0 10000100 00111000000000000000000
+.0000001101011
120
0 01111000 10101100000000000000000

Converting Decimal Fractions to Binary Reals


If a decimal fraction can be easily represented as a sum of fractions in the form (1/2 + 1/4 + 1/8 + ... ), it is fairly easy to discover the corresponding binary real. Here are a few simple examples

Decimal Fraction
Factored As...
Binary Real
1/2
1/2
.1
1/4
1/4
.01
3/4
1/2 + 1/4
.11
1/8
1/8
.001
7/8
1/2 + 1/4 + 1/8
.111
3/8
1/4 + 1/8
.011
1/16
1/16
.0001
3/16
1/8 + 1/16
.0011
5/16
1/4 + 1/16
.0101

 

Binary Coded Decimal (BCD)

Binary Coded Decimal(BCD) is a way to express each of the decimal digits with a

binary code. There are only ten code groups in the BCD system. The 8421 code is a

type of BCD code. In BCD each decimal digit , 0 through 9 is represented by a binary

code of four bits. The designation of 8421 indicates the binary weights of the four

bits (23,22,21,20). The largest 4-bit code is 1001. The numbers 1010, 1011, 1100, 1101,

1110, and 1111 are called forbidden numbers. The following table represents the

decimal and 8421 equivalent numbers.

 

Decimal digit   0             1          2          3     4     5     6     7     8           9

BCD                  0000  0001  0010  0011  0100  0101  0110  0111  1000  1001

 

Alphanumeric code

Computers, printers and the other devices must process both alphabetic and numeric information. Serial coding systems have been developed to represent alphanumeric information as a series of 1’s and 0’s. The characters to be coded are alphabets(26),numerals (10) and special characters such as +,-, /,*, $ etc,

In order to code a character, string of binary digits is used. In order to ensure uniformity in coding, two standard codes have been used.

1. ASCII: American Standard Code for Information Interchange.

2. EBCDIC: Extended Binary Coded Decimal Interchange Code. It is an 8 bit

code.

ASCII is 7-bit code of the form X6, X5, X4, X3, X2, X1, X0 and is used to code two types of information. One type is the printable character such as alphabets, digits and special characters. The other type is known as control characters which represent the coded information to control the operation of the digital computer and are not printed.

 

 

 

0 comments:

Post a Comment

 
Copyright © ComPutEr???