Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Lecture 2: Supplementary Note on Base Conversions Instructor: Yong Kim (Section 1) Motivation: To successfully design a digital system, we must able to represent the numbers and characters from our everyday life to their binary equivalent. Here, we first focus on how a decimal number (base 10) can be converted to a number in other bases. In next few lectures, we will study how characters can be represented in a binary system. 3,468 in decimal number system (or base 10) represents followings: 3,468 = 3 * 1000 + 4 * 100 + 6 * 10 + 8 = 3 * 103 + 4 * 102 + 6 * 101 + 8 * 100 In general, any decimal number can be decomposed as: an-1 an-2 … a1 a0 = an-1* 10n-1 + an-2* 10n-2 + … + a1* 101 + a0* 100 We can generalize this representation to other bases. For a number in base r (we will use [an-1 an-2 … a1 a0] r to denote such number), it represents [an-1 an-2 … a1 a0] r = an-1* rn-1 + an-2* rn-2 + … + a1* r1 + a0* r0 Now, it should be obvious that a number also CAN BE represented in OTHER bases. For example, a decimal number 1310 equals to 11012 since 13 = 1*8 + 1*4 + 0*2 + 1*1 = 1*23 + 1*22 + 0*21 +1*2. Algorithm: To convert the number part (integer part) to other base (radix): Repeatedly divide the number by the radix you want to convert to and save the remainders. The new radix digits are the mod remainders in reverse order of computation. For example, we can convert 3510 to base 8 by 35/8 = 4 + 3/8, where quotient is 4 and the mod remainder is 3 take the quotient, 4, divide it by 8 again, 4/8 = 0 + 4/8, where quotient is 0 and the mod remainder is 4 since the quotient is now 0, we have nothing more to do (we are done). Now, we can reconstruct the number by listing all mod remainders in reverse order, 4 then 3. Thus, we have 438 = 3510. Now, the question you can ask yourself is how does the repeated division work? For a decimal number [cn-1 cn-2 … c1 c0]10, there exist an equivalent representation in radix r, [an-1 an-2 … a1 a0]r. We want to find the set of this unique coefficient so that we can express our decimal number in radix r. When we divide [cn-1 cn-2 … c1 c0]10 by r, we get a quotient and a remainder a0/r or a mod remainder a0. (an-1* rn-1 + an-2* rn-2 + … + a1* r1 + a0* r0) / r = an-1* rn-2 + an-2* rn-3 + … + a1 + a0 /r Each time, we divide the quotient term by r, we reduce its power by 1 and end up with the ak-1/r as a remainder or ak-1 as mod remainder, where k is the number of times the division is performed. We repeat this for n times (until quotient term becomes zero), then we end up with n mod remainders, last one being an-1. Now, we found all n coefficient of [an-1 an-2 … a1 a0]r, and we simply list all mod remainders in reverse order. You should note that this algorithm works for converting a number from any base to any other base! Similarly to , fractional part of radix r is expressed as [0. a-1 a-2 a-3 a-4 … a-m]r = a-1* r-1 + a-2* r-2+ a-3* r-3+ a-4* r-4+ … a-m* r-m Algorithm: To convert the fractional part: Repeatedly multiply the fraction by the radix and save the integer digits that result. The new radix fraction digits are the integer numbers in computed order. For example, to convert 0.687510 to base 2, we repeatedly multiply the fractional part by 2 until we can 0 for fractional part or desired accuracy is obtained. 0.6875 * 2 = 1.3750, 0.3750 * 2 = 0.7500, 0.7500 * 2 = 1.5000, 0.5000 * 2 = 1.0000, 0.0000 integer digit = 1 integer digit = 0 integer digit = 1 integer digit = 1 (nothing more to do) Now, we simply read off integer digits in the forward direction: 0.10112. You can show why this repeated multiplication algorithm works by similar reasoning as above. You should try to do this in your spare time. Alternatively, we can use a summation notation to represent above expression: i n-1 (Number) = ai ri aj r j r j = -m i=0 (Integer Portion) + (Fraction Portion) You now should be able to convert any number with both integer and fractional part to any other bases by simply decomposing it to an integer part and fractional part, find the representation separately then merge them using a radix point (“.”). For example, 46.687510 in base 2 is 1011102 + 0.10112 or 101110.10112.