1. Introduction to Number Representation Systems
Total Page:16
File Type:pdf, Size:1020Kb
VHDL Design and Simulation number_representation_all7.fm - 1 Dr. Anthony D. Johnson 1. Introduction to Number Representation Systems Numbers do exist as what they are - the result of counting; they do not need to be written down to come into existence. Therefore, the often encountered jargon terms: "binary numbers", "octal numbers", "decimal" and "hexadecimal" numbers do not exist as different kinds of numbers. What these jargon terms refer to is how the numbers are recorded/written down. These terms refer to the different number representations in writing: binary number representation, octal number representation, decimal number representation, and hexadecimal number representation. Over the time, there have been invented many different ways in which numbers can be represented in various physical media. Looking just at the writing for visual reference, all of the following are different representations of the number fifty, fifty = 50 = 1100102 = 628 = 5010 = 3216 = L or, all of the following are the representations of the number fifty-two, fifty-two = 52 = 1101002 = 648 = 5210 = 3416= LII, or, for the year numbers in Roman representation MCMXCVIII=199810 while, neither one of them is either a binary, octal, etc. number. To bring more order into the picture, we can remind ourselves that our every day’s writing of fifty-two in the decimal representation is a shorthand notation for the numerical expression, 1 0 510 + 210 = 50 + 2 =5210 . (1-1) The following binary representation of the number fifty1100102 is a shorthand notation of the same type as (1-1) 5 4 3 2 1 0 1100102 = 12 + 12 + 02 + 02 + 12 + 02 = 32 + 16 +0+0+ 2 +0 = 50 . (1-2) Our commonly known decimal number representation system belongs to the same class of Positional Number Representations, which is the common form of the following often used number representations: - decimal, - binary, - octal, - hexadecimal. 1/17/19 VHDL Design and Simulation number_representation_all7.fm - 2 Dr. Anthony D. Johnson POSITIONAL REPRESENTATION OF POSITIVE MIXED NUMBERS Mixed number: N = In{N} + Fr{N} Radix r representation of N: Nr = In{Nr} + Fr{Nr} In{Nr} Fr{Nr} } } Nr = In{Nr} + Fr{Nr} = (an-1an-2... a2a1ao.a-1a-2 ... a-m)r (1-3) fractional point Representation (1-4) is the Expanded positinal representation of the Shorthand form (1-3), n-1 n-2 2 1 0 -1 -2 -m Nr = an-1r + an-2r +... a2r + a1r + a0r + a-1r + a-2r + ... +a-mr (1-4) In the positional representation (1-3), - Nr is the radix r representation of a mixed positive number N, - r is the radix (base) of the representation, that is itself a positive integer number, i - ai is the coefficient to the radix power r , with ai {r-1,r-2,...,2,1,0}, and {r-1,r-2,...,2,1,0} = set of available digits in radix r representation, - n is the number of digits needed for the representation of the integer part of Nr, - m is the number of digits needed for the representation of the fractional part of Nr, - when the number of digits available in hardware is greater than the number of digits needed for the integer part of Nr, leading zeros are prepended in hardware to the integer part, - when the number of digits needed for representation of the given number N, is greater than the number of digits that are provided by the hardware medium being used, the representation of Nr is not possible in that medium. 1/17/19 VHDL Design and Simulation number_representation_all7.fm - 3 Dr. Anthony D. Johnson 2. Performing Arithmetic in Binary Representation Manual addition and multiplication of numbers recorded in binary representation can be conveniently performed following thesame rules for carrying out these two operations in decimal representation. 2.1 Procedure for Manual Subtraction of Positive Integers in Binary Representation The procedure for manual subtraction is formally the same for positional representation in all radixes. So it is practically similar to the familiar procedure used for decimal representation. The only difference of practical concern is in the step of borrowing, where in the binary representation two units are borrowed from the next higher position digit, instead of the ten units borrowed in decimal representation. As an example we present here the detailed procedure of calculating the “two’s complement” of N= seven, represented in n=4 bits binary representation, ~ 4 3 2 1 0 N = 2n- N = 24 - N = 10000 - 0111 = 1001 , 2 2 2 2 2 2 2 2 1 0 0 0 0 - 0 1 1 1 1 0 0 1 A position by position evaluation of the difference 100002- 01112 proceeds as follows, - at position 20: subtracting one from zero requires borrowing one unit of the 21 position of the minuend, which unit has the value of two in the position of 20, so one obtains (2-1)20=1 as the LSB of the result; - at position 21: the fact that one unit has already been borrowed from the 21 position of the minuend can be accounted for by adding 1 to 21 position of the subtrachend, so one needs to subtract 1+1=2 from zero; again, one borrows one unit of the next higher position 22 of the minuend, so one calculates (2-2)21=0 as the value to be placed in the 21 position of the result; - at position 22: one accounts for the one unit borrowed from 22 position of the minuend, by adding 1 to position 22 of the subtrachend, so one ought to subtract 1+1=2 from the unaltered value zero at the position 22 of the subtrachend; therefore, one borrows now one unit from the next higher position 23 of the minuend, and obtains (2-2)22=0 as the value to be placed at the position 22 of the result; - at position 23: one accounts for the one unit borrowed from position 23 of the minuend, by adding 1 to position 23 of the subtrachend, so one ought to subtract 0+1=1 from the unaltered value zero at the position 23 of the minuend, one borrows one unit of the next higher position 24 of the minuend (which is worth two units at the position 23) and one obtains (2-1)23=1 as the value to be placed at the MSB position of the result; - at position 24: one could consider that there is nothing more to be done at this position since the 1 at position 24 of the minuend has been already consumed by the borrowing invoved in the calculation at position 23; alternatively, one can account for the one unit borrowed from position 24 of the minuend, by adding 1 to the implicit zero at the nonexistent position 24 of the subtrachend, so one needs to subtract 0+1=1 from the unaltered value 1 at the position 24 of the minuend, whereby the result (1-1)24=0 becomes a leading zero, that can be left out of the total result obtained by this hand calculation. 1/17/19 VHDL Design and Simulation number_representation_all7.fm - 4 Dr. Anthony D. Johnson 2.2 Procedure for Manual Division of Positive Integers in Binary Representation The Algorithm for Manual Division of positive integers in binary representation is formally described by the following five steps: STEP1: align positional values of the divisor undernieth the Active Part of Dividend (APD), which APD satisfies the following two conditions: - APD represents a number that is not smaller than the divisor, - APD contains the minimal number of digits; When such an APD does not exist, the quotient is equal to zero, and the remainder is equal to the dividend; otherwise procede to STEP2. STEP2: dividing APD by the divisor necessarily makes the next digit of the quotient equal to 1, so digit 1 is written above the least significant digit (LSD) of the current APD; STEP3: subtract the divisor from the current APD; STEP4: in forming the next APD (to which the division by divisor will be next applied) append to the current APD the MSD of the yet unprocessed part of the dividend; STEP5: in this step, two cases are possible: Case 1 when APD represents a number that is not smaller than divisor, perform STEP2 through STEP5, Case 2 otherwise, - append a digit 0 to the current quotient’s expression, - when there are still unprocessed digits of the dividend: - apply STEP4 through STEP5 to the current expression of APD; - otherwise, - the Quotient’s representation has been completed, - the last result of STEP3 represents the Remainder’s representation. Example 1.6 illustrates the application of the Manual Division Algorithm. Example 1.6 Division in binary representation: Divide 11101112 by 10012. APD 1 1 0 1 Quotient Divisor 1 0 0 1 1 1 1 0 1 1 1 Dividend 1 0 0 1 Case 1 APD 1 0 1 1 1 0 0 1 Case 2 APD 1 0 1 Case 1 APD 1 0 1 1 1 0 0 1 1 0 Remainder 1/17/19 VHDL Design and Simulation number_representation_all7.fm - 5 Dr. Anthony D. Johnson 1.3 Converting a Number’s Representations Between two Bases/Radixes - p30 An often encountered practical situation is that a number N is available as represented in one of positional representations, but a different positional representation of N is needed by some processing step that is to be performed. This creates a conversion task that can be formally specified as, Problem: Number Representation Conversion between Two Radixes Problem Statement: Given is: NrA radix rA representation of a positive mixed number N, rA, rB two radixes (bases), (rB)rA representation of the radix rB in radix rA representation, (rA)rB representation of the radix rA in radix rB representation.