Download presentation
Published byDorothy Maxwell Modified over 9 years ago
1
Dr. Bernard Chen Ph.D. University of Central Arkansas
Data Representation Dr. Bernard Chen Ph.D. University of Central Arkansas
2
Outline Data Representation Compliments
Subtraction of Unsigned Numbers using r’s complement How To Represent Signed Numbers Floating-Point Representation
3
Data Types The data types stored in digital computers may be classified as being one of the following categories: numbers used in arithmetic computations, letters of the alphabet used in data processing, and other discrete symbols used for specific purposes. All types of data are represented in computers in binary-coded form.
4
Radix representation of numbers
• Radix or base: is the total number of symbols used to represent a value. A number system of radix r uses a string consisting of r distinct symbols to represent a value.
5
Radix representation of numbers
Example: convert the following number to the radix 10 format The positions indicate the power of the radix. Start from the decimal point right to left we get 0,1,2,3,4 for the whole numbers. And from the decimal point left to right We get -1, -2 for the fractions = 9x x x x x x x10-2
6
Binary Numbers Binary numbers are made of binary digits (bits):
0 and 1 Convert the following to decimal (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10
7
Example Use radix representation to convert the binary number (101.01) into decimal. The position value is power of 2 /22 = (101.01)2 (5.25)10 = x x x x 2-2 7
8
Converting an Integer from Decimal to Another Base
For each digit position: Divide the decimal number by the base (e.g. 2) The remainder is the lowest-order digit Repeat the first two steps until no divisor remains. For binary the even number has no remainder ‘0’, while the odd has ‘1’ 8
9
Converting an Integer from Decimal to Another Base
Quotient Remainder Coefficient Example for (13)10: 13/2 = (12+1)½ a0 = 1 6/2 = ( 6+0 )½ a1 = 0 3/2 = (2+1 )½ a2 = 1 1/2 = (0+1) ½ a3 = 1 Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2
10
Converting a Fraction from Decimal to Another Base
For each digit position: Multiply decimal number by the base (e.g. 2) The integer is the highest-order digit Repeat the first two steps until fraction becomes zero.
11
Converting a Fraction from Decimal to Another Base
Example for (0.625)10: Integer Fraction Coefficient 0.625 x 2 = a-1 = 1 0.250 x 2 = a-2 = 0 0.500 x 2 = a-3 = 1 Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2
12
DECIMAL TO BINARY CONVERSION (INTEGER+FRACTION)
(1) Separate the decimal number into integer and fraction parts. (2) Repeatedly divide the integer part by 2 to give a quotient and a remainder and Remove the remainder. Arrange the sequence of remainders right to left from the period. (Least significant bit first) (3) Repeatedly multiply the fraction part by 2 to give an integer and a fraction part and remove the integer. Arrange the sequence of integers left to right from the period. (Most significant fraction bit first)
13
. (Example) (41.6875)10 ® (?)2 Integer = 41, Fraction = 0.6875 Integer
Overflow Fraction X by 2 .6875 1 .3750 .750 .5 Integer remainder /2 1 20 10 5 2 Closer to the point . The first procedure produces 41= 1 x x x x x = (101001) 0.6875=0.1011 (10) = (2)
14
Octal Numbers Octal numbers (Radix or base=8) are made of octal digits: (0,1,2,3,4,5,6,7) How many items does an octal number represent? Convert the following octal number to decimal (465.27)8 = 4x82 + 6x81 + 5x80 + 2x x8-2 14
15
Counting in Octal 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 15
16
Converting an Integer from Decimal to Octal
For each digit position: Divide decimal number by the base (8) The remainder is the lowest-order digit Repeat first two steps until no divisor remains.
17
Converting an Integer from Decimal to Octal
Example for (175)10: Integer Quotient Remainder Coefficient 175/8 = / a0 = 7 21/8 = / a1 = 5 2/8 = / a2 = 2 Answer (175)10 = (a2 a1 a0)2 = (257)8
18
Converting an Integer from Decimal to Octal
For each digit position: Multiply decimal number by the base (e.g. 8) The integer is the highest-order digit Repeat first two steps until fraction becomes zero.
19
Converting an Integer from Decimal to Octal
Example for (0.3125)10: Integer Fraction Coefficient x 8 = a-1 = 2 x 8 = a-2 = 4 Answer (0.3125)10 = (0.24)8 Combine the two ( )10 = (257.24)8 Remainder of division Overflow of multiplication
20
Hexadecimal Numbers Hexadecimal numbers are made of 16 symbols:
(0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) Convert a hexadecimal number to decimal (3A9F)16 = 3x x x x160 = Hexadecimal with fractions: (2D3.5)16 = 2x x x x16-1 = Note that each hexadecimal digit can be represented with four bits. (1110) 2 = (E)16 Groups of four bits are called a nibble. (1110) 2
21
Example Convert the decimal number ( )10 into hexadecimal number. ( )10 (6B.01)16 Overflow Fraction X by 16 .0625 1 .0000 Integer remainder 107 Divide/16 6 11=B Closer to the period .
22
The Growth of Binary Numbers
20=1 1 21=2 2 22=4 3 23=8 4 24=16 5 25=32 6 26=64 7 27=128 n 2n 8 28=256 9 29=512 10 210=1024 11 211=2048 12 212=4096 20 220=1M 30 230=1G 40 240=1T Mega Giga Tera 22
23
Conversion Between Number Bases
Octal(base 8) Decimal(base 10) Binary(base 2) Hexadecimal (base16) We normally convert to base 10 because we are naturally used to the decimal number system. We can also convert to other number systems 23
24
One to one comparison Binary, octal, and hexadecimal similar
Easy to build circuits to operate on these representations Possible to convert between the three formats
25
Converting between Base 16 and Base 2
3A9F16 = 3 A 9 F Conversion is easy! Determine 4-bit value for each hex digit Note that there are 24 = 16 different values of four bits which means each 16 value is converted to four binary bits. Easier to read and write in hexadecimal. Representations are equivalent!
26
Converting between Base 16 and Base 8
3A9F16 = 3 A 9 F = 3 5 2 3 7 Convert from Base 16 to Base 2 Regroup bits into groups of three starting from right Ignore leading zeros Each group of three bits forms an octal digit (8 is represented by 3 binary bits).
27
Example Convert 101011110110011 to a. octal number
b. hexadecimal number a. Each 3 bits are converted to octal : (101) (011) (110) (110) (011) = (53663)8 b. Each 4 bits are converted to hexadecimal: (0101) (0111) (1011) (0011) B = (57B3)16 Conversion from binary to hexadecimal is similar except that the bits divided into groups of four.
28
ASCII Code American Standard Code for Information Interchange
ASCII is a 7-bit code, frequently used with an 8th bit for error detection (more about that in a bit). Character ASCII (bin) ASCII (hex) Decimal Octal A 41 65 101 B 42 66 102 C 43 67 103 … Z a 1 ‘ 28
29
Outline Data Representation Compliments
Subtraction of Unsigned Numbers using r’s complement How To Represent Signed Numbers Floating-Point Representation
30
Binary Addition Example Add (11110)2 to (10111)2 1 1 1 1 1 1 carries
1 1 1 carry (111101)2 + (10111) 2 = ( )2
31
Binary Subtraction 1+1=2 1 10 borrows 0 10 10 0 0 10 1 0 0 1 1 0 1
We can also perform subtraction (with borrows). Example: subtract (10111) from ( ) 1+1=2 borrows ( )2 - (10111)2 = ( )2
32
Subtraction using addition
Conventional addition (using carry) is easily implemented in digital computers. However; subtraction by borrowing is difficult and inefficient for digital computers. Much more efficient to implement subtraction using ADDITION OF the COMPLEMENTS of numbers.
33
Complements of numbers
(r-1 )’s Complement Given a number N in base r having n digits, the (r- 1)’s complement of N is defined as (rn - 1) - N For decimal numbers the base or r = 10 and r- 1= 9, so the 9’s complement of N is (10n-1)-N 99999……. - N 9 9 9 9 9 - Digit n Digit n-1 Next digit Next digit First digit
34
9’s (10-1) complement Examples
5 4 6 7 2- Find the 9’s complement of and 12389 The 9’s complement of is = and the 9’s complement of is = 4 5 3 2 9 9 9 9 9 9 9 - 1 2 3 8 9 8 7 6 1
35
l’s (2-1) complement - For binary numbers, r = 2 and r — 1 = 1,
r-1’s complement is the l’s complement. The l’s complement of N is (2^n- 1) - N. Bit n-1 Bit n-2 ……. Bit 1 Bit 0 1 1 1 1 1 - Digit n Digit n-1 Next digit Next digit First digit
36
l’s complement Find r-1 complement for binary number N with four binary digits. r-1 complement for binary means 2-1 complement or 1’s complement. n = 4, we have 24 = (10000)2 and = (1111)2. The l’s complement of N is (24 - 1) - N. = (1111) - N
37
l’s complement - - The complement 1’s of 1011001 is 0100110
1 1 1 The complement 1’s of is 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 The 1’s complement of is 1 1 1
38
r’s Complement - Given a number N in base r having n digits,
the r’s complement of N is defined as rn - N. For decimal numbers the base or r = 10, so the 10’s complement of N is 10n-N. 100000……. - N 1 - Digit n Digit n-1 Next digit Next digit First digit
39
10’s complement Examples
Find the 10’s complement of and 12389 The 10’s complement of is = and the 10’s complement of is = Notice that it is the same as 9’s complement + 1. 1 - 5 4 6 7 4 5 3 3 1 - 1 2 3 8 9 8 7 6 1 1
40
2’s complement - For binary numbers, r = 2,
r’s complement is the 2’s complement. The 2’s complement of N is 2n - N. 1 - Digit n Digit n-1 Next digit Next digit First digit
41
2’s complement Example - - The 2’s complement of 1011001 is 0100111
- The 2’s complement of is 1 1 1 1 1 1 1 1 1 - The 2’s complement of is 1 1 1 1 1 1 1 1
42
Fast Methods for 2’s Complement
The 2’s complement of binary number is obtained by adding 1 to the l’s complement value. Example: 1’s complement of is (invert the 0’s and 1’s) 2’s complement of is =
43
Fast Methods for 2’s Complement
The 2’s complement can be formed by leaving all least significant 0’s and the first 1 unchanged, and then replacing l’s by 0’s and 0’s by l’s in all other higher significant bits. Example: The 2’s complement of is Leave the two low-order 0’s and the first 1 unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in the four most significant bits.
44
Examples Finding the 2’s complement of ( )2 Method 1 – Simply complement each bit and then add 1 to the result. ( )2 [N] = 2’s complement = 1’s complement ( )2 +1 =( )2 Method 2 – Starting with the least significant bit, copy all the bits up to and including the first 1 bit and then complement the remaining bits. N = [N] = 44
45
Outline Data Representation Compliments
Subtraction of Unsigned Numbers using r’s complement How To Represent Signed Numbers Floating-Point Representation
46
Subtraction of Unsigned Numbers using r’s complement
(1) if M N, ignore the carry without taking complement of sum. (2) if M < N, take the r’s complement of sum and place negative sign in front of sum. The answer is negative.
47
Example 1 (Decimal unsigned numbers),
perform the subtraction = M > N : “Case 1” “Do not take complement of sum and discard carry” The 10’s complement of is Therefore: M = 10’s complement of N =+86750 Sum= Discard end carry 105= Answer = no complement 47
48
Now consider an example with M <N.
The subtraction produces negative Using the procedure with complements, we have M = 10’s complement of N = Sum = Take 10’s complement of Sum = -40718 The number is : Place negative sign in front of the number: 48
49
Subtract by Summation Subtraction with complement is done with binary numbers in a similar way. Using two binary numbers X= and Y= We perform X-Y and Y-X
50
X-Y X= 2’s com. of Y= Sum= Answer=
51
Y-X Y= 2’s com. of X= Sum= There’s no end carry: answer is negative (2’s complement of )
52
BINARY ADDER Binary adder is constructed with full-adder circuits connected in cascade.
53
FULL-ADDER •It has 3 input and 2 output
To implement an arithmetic adder for multiple-bit inputs, we need to treat the carry out from the lower bit as a third input ( it becomes carry in for the current bit) in addition to the two input bits at the current bit position. X1 Y1 Z1 S 1 C1 X0 Y0 Z0 S0 C0 + 53 53
54
Full- Adder It adds 3-bits, it has 3-inputs and 2-outputs
We will use x, y and z for inputs and s for sum and c for carry are the two outputs. The truth table x y z c s 1
55
Full Adder Putting them together we get: S= x y z
C= z (x y) + xy The logic diagram for the full adder 55 55
56
BINARY ADDER Binary adder is constructed with full-adder circuits connected in cascade.
57
Arithmetic Microoperations
Arithmetic subtraction: R3 R1 + R2’ + 1 where R2 is the 1’s complement of R2. Adding 1 to the one’s complement is equivalent to taking the 2’s complement of R2 and adding it to R1.
58
BINARY ADDER-SUBTRACTOR
• The addition and subtraction operations can be combined into one common circuit by including an exclusive-OR (XOR) gate with each full-adder.
59
BINARY ADDER-SUBTRACTOR
60
BINARY ADDER-SUBTRACTOR
• M = 0: Note that B XOR 0 = B. This is exactly the same as the binary adder with carry in C0 = 0. M = 1: Note that B XOR 1 = B’ (flip all B bits). The outputs of the XOR gates are thus the 1’s complement of B. M = 1 also provides a carry in 1. The entire operation is: A + B’ + 1.
61
Outline Data Representation Compliments
Subtraction of Unsigned Numbers using r’s complement How To Represent Signed Numbers Floating-Point Representation
62
How To Represent Signed Numbers
Plus and minus signs used for decimal numbers: (or +25), -16, etc. For computers, it is desirable to represent everything as bits. Three types of signed binary number representations: signed magnitude, 1’s complement, and 2’s complement
63
1. signed magnitude In each case: left-most bit indicates sign: positive (0) or negative (1). Consider 1. signed magnitude: = 1210 Sign bit Magnitude = Sign bit Magnitude
64
2. One’s Complement Representation
The one’s complement of a binary number involves inverting all bits. To find negative of 1’s complement number take the 1’s complement of whole number including the sign bit. = 1210 Sign bit Magnitude = Sign bit 1’complement
65
3. Two’s Complement Representation
The two’s complement of a binary number involves inverting all bits and adding 1. To find the negative of a signed number take the 2’s the 2’s complement of the positive number including the sign bit. = 1210 Sign bit Magnitude = Sign bit 2’s complement
66
Sign addition in 2’s complement
The rule for addition is add the two numbers, including their sign bits, and discard any carry out of the sign (leftmost) bit position. Numerical examples for addition are shown below. Example: In each of the four cases, the operation performed is always addition, including the sign bits. Only one rule for addition, no separate treatment of subtraction. Negative numbers are always represented in 2’s complement. 66 66
68
Overflow Overflow example: +70 0 1000110 -70 1 0111010
= =
69
Overflow An overflow cannot occur after an addition if one number is positive and the other is negative, since adding a positive number to a negative number produces a result that is smaller than the larger of the two original numbers. An overflow may occur if the two numbers added are both either positive or negative.
70
Outline Data Representation Compliments
Subtraction of Unsigned Numbers using r’s complement How To Represent Signed Numbers Floating-Point Representation
71
Floating-Point Representation
is represented in floating-point with a fraction and an exponent as follows: Fraction Exponent Scientific notation : 10+3
72
Floating-Point Representation
32-bit floating point format. Leftmost bit = sign bit (0 positive or 1 negative). Exponent in the next 8 bits. Use a biased representation. Final portion of word (23 bits in this example) is the significand (sometimes called mantissa).
73
Example sign 1bit sign EXP EXP 8bit Significant 23bit
Convert the following number; into floating point format to fit in 32 bit register. Convert the number from decimal into binary Normalize all digits including the fraction to determine the exponent. x 25 1 1 sign 1bit sign EXP EXP 8bit Significant 23bit
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.