Sie sind auf Seite 1von 45

>> 4-BIT BCD CODES >> 6-BIT BCD CODES >> 8-BIT BCD CODES >> ZONED-DECIMAL &

PACKED DECIMAL FORMATS

INTRODUCTION HOW DOES A COMPUTER REPRESENT THE NUMERICAL DATA IN BINARY FORMAT? Base-2 digits [Straight Binary] BCD [Binary-Coded Decimal] Types of 4-bit BCD formatted codes >>Weighted 8-4-2-1 BCD Codes >>Weighted 4-2-2-1 BCD Codes* >>Non-weighted XS-3 BCD Codes

Binary Codes Binary codes can be used to represent information. The most common formats are pure binary (for numbers), which is weighted and ASCII (for characters) which is unweighted. What is weighted? It is positional notation, e.g., 3456 = 3 103 + 4 102 + 5 101 + 6 100. For binary, this could be: 0111 = 0 23 + 1 22 + 1 21 + 1 20. 0 + 4 + 2 + 1 = 7. To distinguish pure binary, you could say it was the 8421 code (from the column weightings).

DECIMAL DIGITS

4-BIT BCD CODES 8-4-2-1 XS-3 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100

0 1 2 3 4 5 6 7 8 9

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Table : the binary representation for 4-bit codes

Example 2 What is the weighted BCD representation for 46910 in a computers memory cells? PRINCIPLE : Add 310 = 00112 for each decimal digit represented by the 8-4-2-1 BCD codes. Decimal Digit 4 6 9 8-4-2-1 BCD Codes 0100 0110 1001 Add 310 = 00112 + 0011 0011 0011 _____________________ The XS-3 BCD codes 0111 1001 1100

0111

1001

1100

XS-3 BCD Codes BCD Codes

6-BIT BCD CODES

WHY 6-BIT BCD CODES WERE BEING CREATED? THE REPRESENTATION ON NON-NUMERIC CHARACTERS & DATA (i.e. 26 Roman alphabetic & some special characters) IT CAN HANDLE UP TO 28 SPECIAL CHARACTERS (i.e. 28 = 26 - 36) MEMORY CELLS REPRESENTATION (2 types)

MEMORY CELLS REPRESENTATION (2 types)

Zone Bits

Numeric Bits

1 1

6-bit cells
2

7-bit cells

Check Bit

RULES Check Bit for parity check with values as follows:0 if the sum in zone & numeric bits is odd. 1 if otherwise (even sum). Zone Bits combinations of two-binary digits Numeric Bits combinations of 4-binary digits

Zone Bits

Numeric Bits

DESCRIPTIONS yZone bits to cluster the binary combination based on the 8-grouped characters. yCheck bits to ensure not a single bit is lost or gained in memory cells when data is internally transmitted, thus to avoid parity of the numeric bits that can only be distinguished by zone bit. Example 3 The use of parity check bit for characters. Check Bit 7 P W 9 0 1 0 1 Zone Bit 00 10 01 00 Numeric Bit 0111 0111 1100 1001

Table : the binary representation for 6-bit codes for alphabets Table : the binary representation for 6-bit codes for numbers Table : the binary representation for 6-bit codes for special characters

GOTO----WORD

A
110001 0110001 1110001

Z
011001 0011001 1011001

I
111001 1111001 0111001

L
100011 0100011 1100011

A
110001 0110001 1110001

H
111000 0111000 1111000

WITH ODD PARITY WITHOUT ODD PARITY

8-BIT BCD CODES

WHY 8-BIT BCD CODES WERE BEING CREATED? TO HANDLE MORE (SPECIAL) CHARACTERS IN MODERN DATA PROCESSING. IT CAN HANDLE UP TO 28 = 256 CHARACTERS
MEMORY CELLS REPRESENTATION

Zone Bits

Numeric Bits

TWO STANDARDS OF 8-BIT BCD CODES IN COMPUTER INDUSTRY >>EBCDIC (Extended Binary-coded Decimal Interchange Code) i) An extension of 6-bit BCD ii) For IBM and IBM compatible >>ASCII (American Standard Code for Information Interchange) i) Extension of the 7-bit BCD ii) For non-IBM computers

EBCDIC represent numerical data in computer but the sign of a number is not encoded by an 8 bit group at the beginning of the number but by a 4 bit group which occupies the zone portion Note: the code for an unsigned(positive) number is the normal digit zone code. Z Z Z Z 8 4 2 1
8-BIT BCD

Zone bits 2

Numeric bits 7 5

1111

0010

1111

0111

1111

0101
Sign indicator

ZONED-DECIMAL & PACKED-DECIMAL FORMATS WHY? To identify the sign of a number which is not encoded by an 8-bit group at the beginning of it in EBCDIC format. RULE Coding of a string of number occupies the zone bits of the right most digit. CODING SIGN

SIGN + unsigned

EBCDIC CODE 1100 1101 1111

Example (ZONED-DECIMAL) Illustrate the zoned-decimal format of memory cell in computers for the number 275, +275 and 275
Unsgd Unsgd Unsgd

1111
Unsgd

0010
2

1111
Unsgd

0111
7

1111
+

0101
5

1111
Unsgd

0010
2

1111
Unsgd

0111
7

1100
-

0101
5

1111

0010

1111 0111

1101

0101

The arithmetic/logic unit of the computer cannot generally handle data in this form Data must be converted to another form before calculation can occur. PACKED DECIMAL FORMAT RULE TO CONVERT TO PACKED DECIMAL FORMAT >Interchange the zone & numeric bits of the right most byte. >Delete the zone bits >Pack the remaining numeric bits together

UNSIGNED

0010 0111 0101 1111


2 7 5

0010 0111 0101 1100


2 7 5

Illustrate the packed-decimal format of memory cell in computers for the number 275, +275 and 275

0010 0111 0101 1101


Packed Decimal Format

MATHEMATICAL ESSENTIAL EXPONENTIAL FORM INTERNAL REPRESENTATION COMPUTER ARITHMETIC

MATHEMATICAL ESSENTIAL

1.APPROXIMATE NUMBERS PROBLEM : Infinite versus Finite number of digits in any number sets, Real, Rational & Irrational, Integer, Transcendental numbers and etc. EFFECTS ON COMPUTING PRECISION, ACCURACY & SENSITIVITY.

TWO IMPORTANT SYMBOLS: The sign of almost/approximately equal () The sign of identical to ( )

SIGNIFICANT DIGITS (Rules) >The non-zero digits is always significant. >The digit 0 is significant if it lies between other significant digits. >The digit 0 never significant when it precedes all the non-zero digits.
Example 1 707.077, 1421 : all digits are significant. 0.000345 : there are three (3) significant digits, i.e. 3, 4, and 5. 7.7700, 7770.0, 0.00077700 are all having significant digits. (Embedded decimal points) 56700000 Embedded decimal point is non-existance, therefore no significant digits unless it is converted to exponential form.

ROUNDING NUMBERS PROBLEM : On how to approximate a numerical value by evaluating another number, i.e. in order to have resulted fewer decimal digits or having a required number of significant digits. GENERAL RULE : Test Digit that refers to the first (left most) digit to be dropped. TYPES OF ROUNDING OFF NUMBERS ROUNDING DOWN : if test digit < 5, then the preceding digits remain unchanged. ROUNDING UP : if the test digit 5, followed by at least one nonzero digit, then the preceding digit is increased by 1 (with carry of 1 if the preceding digit is 9). ODD-ADD RULE : if the test digit with only 0s following, then the preceding digit is unchanged if and only if it is even, but increased by 1 if odd.

Example 2 Round off the following number to 4 decimal place. 1.73482 1.7348 0.000037 0.0000 0.567675 0.5677 0.000911 0.0009 Round off each of the following numbers to 1 decimal point. 1.152 1.2 22.25070 22.3 3.356 3.4 7.85 7.9 9.9500 10.0 Round off each number to 3 significant digits 0.77777 0.778 5.43 5.4321 66.6503 66.7 889 888.5 333.5 334 111.500 112

TRUNCATING (CHOPPING) NUMBERS PROBLEM : When a computer performs calculations, the resulting numbers have more digits then the memory cells allocations. SOLUTION : Truncating refers to the human pre-programmed operations on computers to save memory space. SETBACK : The precision & accuracy will be definitely affected, and thus it increases the percentage of truncating error comparatively to the percentage of round-off error. Example 3 Truncate the following numbers to 3 significant digits. 88.77 88.7 -7.8989 -7.89 999.111 999 -0.012345 -0.0123

1.ABSOLUTE VALUE DEFINITION a = a -a if a 0 if a < 0

Find the absolute values for the following numbers; 15, -8, 0 and -0.075 Solution : | 15 | = 15, |-8| = 8, |0| = 0 and |-0.075| = 0.075 Evaluate the followings. 3 8 = 5 = 55 3 8 =38=5 8 = (8) = 8

EXPONENTIAL FORM
WHY? To write an exceptionally ultra large or ultra small numbers as decimal number times power of 10.Also called as scientific notation in computing science.

Example (DECIMAL REPRESENTATION) Decimal Number 768 0.000768 Normalized Exponential Form 0.768 x 103 0.768 x 10-3 Mantissa Exponent Scientific Notation 7.68 x 102 7.68 x 10-4

0.768 0.768

3 3

Example (BINARY REPRESENTATION)

Decimal Number 1010.1 -0.001111 0.1

Normalized Exponential Form 0.10101 x 24 0.11110 x 2-2 0.10000 x 2-0

Mantissa 0.10101 0.11110 0.10000

Exponent 4 -2 0

Remark : Computers will store 5 digits of mantissa by either adding 0 or truncating the bits.

INTERNAL REPRESENTATION INTEGER REPRESENTATION It is basically a straight binary coding as it encodes the entire number as a whole in binary form. DEFINITION Word list of bits treated as a unit. Length of the word the number of bits Assumption : Computer processing use words of fixed length of 32 bits. Example (INTEGER REPRESENTATION) 43210 = 1101001112

00 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 1 1

Fixed length 32-bit

Example: the computer stores -423 in a memory location by taking the 1s complement of the above representation for 423 and then adding 1

-423 11 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 0 0 1
The largest (positive) integer that can be stored in a 32-bit memory location = 231-1 The smallest (negative) integer that can be stored in a 32-bit memory location = -231

FLOAT-POINT REPRESENTATION Memory Representation

24 bit 1 bit 7 bit

Sign bit Unit block

Exponent bit block

Mantissa bit block

Such numbers are stored and processed in their binary exponential forms. The memory location divided into 3 blocks of bits

True exponent-characteristic relationship

True Exponent Characteristic (in decimal) Characteristic (in binary)

-64 0 0000000

-63 1 0000001

-62 2 0000010

0 64 1000000

1 65 1000001

63 127 1111111

Example 9 Given a number - 419.812510 . Illustrate the float-point internal representation. Solution STEP 1 : Convert the decimal number to its binary form. 419.812510 = 110100011.11012 STEP 2 : Normalized the result from step 1. 110100011.11012 = 0.11010001111012 x 29 STEP 3 : Find the true exponent by adding the sum of 64 to the exponent obtained in step 2. 910 + 6410 = 7310 = 10010012 STEP 4 : Store the binary representation in 32-bit block Memory STEP 5 : Sign bit value is one (1) if the number is negative, otherwise the value is zero (0) if positive.
1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0
1 bit Sign bit Unit block

7-bit Exponent bit block

24 bit Mantissa bit block

Example 9 Given a number - 419.812510 . Illustrate the float-point internal representation. Solution STEP 1 : Convert the decimal number to its binary form. 419.812510 = 110100011.11012 STEP 2 : Normalized the result from step 1. 110100011.11012 = 0.11010001111012 x 29 STEP 3 : Find the true exponent by adding the sum of 64 to the exponent obtained in step 2. 910 + 6410 = 7310 = 10010012 STEP 4 : Store the binary representation in 32-bit block Memory STEP 5 : Sign bit value is one (1) if the number is negative, otherwise the value is zero (0) if positive.
1 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0
1 bit Sign bit Unit block

7-bit Exponent bit block

24 bit Mantissa bit block

Because 7-bit {exponent bit block} therefore exponent is represented in biased form, i.e. excess 2n-1, where n = 7, so we obtain excess 29 representation of +9 as 26 + 9 = 64 + 9 = 73 = 10010012
1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0

7-bit

In certain computer, 9 bits are used for the representation of a floating point Number. a) Give the binary representation of 5.7510 b) What decimal number is represented by 1101011002? c) What is the range of exponents that can be stored? d) What is the range of decimal numbers that can be stored? e) What is the error in the representation?

Sign of fraction

Biased exponents (4 bits)

Magnitude of fractions (4 bits)

a) 5.75 10 = 101.112 Normalize binary number 101.112 ----- 0.10111 x 23 The exponent is therefore +3 Therefore exponent represented in biased form,..where n = 4 23 + 3 = 8 + 3 = 1110 = 10112

1 0

2 1

3 0

4 1

5 1

Sign of Fraction --- if positive, the leftmost bit is 0. Magnitude of the fraction: this is simply, the normalized binary fraction obtained earlier i.e. .10111

Mantissa occupies 4 bits. Therefore, we have to truncate the least Significant bit of the mantissa, storing only 1011. The internal representation of 5.75 is obtained as follows 1 0 2 1 3 0 4 1 5 1 6 7 8 1 9 1 1 0

d) To find the error, convert the bits in the representation to determine the actual num Represented, the subtract from the original number Actual number represented 0101110112 : 0.1011 x 23 = 101.12=5.510 Error in the representation => 5.75-5.5 = 0.25 b) What decimal number is represented by 1101011002? Divide the representation into three parts

1 1

2 1

3 0

4 1

5 0

6 1

7 1

8 0

9 0

Sign bit =1 so its negative Exponent : m + 23 = 10102 = 1010 Therefore m = 10 - 8 = 2 Mantissa is .11002 Thus the number is .1100 x 22 = 11.002 = -3.010

d) Range of exponents that can be stored: 4 bits are used for the exponent Smallest number that can be stored is 00002 = 010 In excess 8 form, 0 would represent e + 8 e + 8 = 0 e = -8 Thus the smallest exponent that can be stored is -8 The largest exponent in 4 bits = 11112 = 1510 In excess 8, e + 8 = 15 e=7 Thus the largest exponent is 7 Range of exponents is -8 to + 7

e) Range of decimal numbers that can be stored: The largest mantissa. This is the fraction with all 1 bits => 0.11112 The largest floating point number that can be stored is 0.1111 x 27=11110002=12010 The smallest = - the largest number = -120 Therefore the range of decimal numbers that can be stored is -120 to +120

Several schemes representing signed integer in a computer. 1. sign-magnitude 2. 1s complement 3. 2s complement All these methods have one common feature: a> the leftmost bit is reserved to represent the sign of the integer B> 0 indicates positive number whie 1 negative number

Sign magnitude: The sign and magnitude (absolute value) of the integer are represented  separately A negative integer, for example is represented by 1 in the leftmost bit and the absolute value in the remaining bits.

Example: for 8-bit machine, the integers 30 and -30 27 26 25 24 23 22 21 20 30: 0 0 0 1 1 1 1 0 -30: 1 0 0 1 1 1 1 0
Its a poor choice for integer representation in modern day computer systems

1s Complement
Left-most bit is initially set to zero. Absolute value of number (binary format) occupies the remaining bit places For a negative number ALL the bits are then complemented (i.e. reversed). Note that this will make the sign bit 1 as it should be.

Example :The 1s complement representation of 30 and -30:


27 26 25 24 23 22 21 20

30 : 0 0 0 1 1 1 1 0 -30 : 1 1 1 0 0 0 0 1 Prob: -0 and +0 are represented differently even though they are the same algebraically

Addition in 1s complement Rule: Carry over of leftmost digit during addition is added back to the bit string Example: -1+5 using 4-bits representation
+1:

1 1

0 0

23 22 21 20

-1 : +5:

1 1 1 0 0 1 1 0 10 1 0 0

0 1 0 0 1 + 0 1 0 1

+4

Try 6 3=? using 6 bits representation

2s complement Positive numbers are treated like ones complement Negative numbers representation obtained by adding 1 to 1s complement representation 1. Start with the absolute value in binary 2. Then complement all the bits 3. Now add 1 to the result The 8-bit 2s complement of representation -30 is 30: 0 0 0 1 1 1 1 0 -30: 11100001 Add 1 +1 11100010

Addition in 2s Complement Adding two 2s complement numbers involve adding the bit strings as an unsigned number and ignoring the carry out of the leftmost bit if there is one Example: Add 92 and -45 in 2s complement using 8-bits 92 = 01011100 -45 = ?? Firstly 45 = 00101101 Complemented = 11010010 Add 1 = 11010011 Therefore -45 = 11010011 92 : 01011100 -45 : + 11010011 1 0 0101111 Drop the leftmost carry bit: =001011112

1.ERRORS & INACCURACIES ARITHMETIC ERRORS >>Absolute Errors >>Relative Errors

Supposed z = 1.427 is the actual (experimental) value of a number and


z ! 1.4

is the approximate (theoretical) value of z. Therefore, Absolute error,

I ! z  z ! 1.427 1.4 ! - 0.00 ! 0.00

Relative error,

0.00 r ! ! 1.427 A

! 0.0021

Thus the percentage of relative error:0.0021 x 100% = 0.21%

Das könnte Ihnen auch gefallen