Number Representations by Nicole Tobias Adapted from text(s): PC Assembly Language by Carter and LINUX Assembly Programming by Neveln
Remember the ENIAC? ENIAC did not use the binary system It s arithmetic processor used vacuum tubes were wired together into rings These worked like old desktop adding machine wheels They were base 0 contraptions
Now All electronic computers to arithmetic using the binary system. Sometimes we express descriptions of computer arithmetic in either binary or related systems such as hexadecimal or octal
Decimal, Binary, Hex, etc. NUMBER SYSTEMS
Decimal Base 0 Composed of digits 0 through 9 A total of 0 digits Each digit of a number has a power of 0 associated with it based on the digit s position For example: 3 = x 0 + 3 x 0 + x 0 0
Converting to Decimal General Formula: Value base0 = n n= digit base n Where value of n is the digit position Convert 3 to base 0 value: Column = n = 3 Digit = d = 3 Base = b = 0 0 0
Converting to Decimal Convert 3 to base 0 value: Position = * 0 0 = * = Position = 3 * 0 = 3 * 0 = 30 Position 3 = * 0 = * 00 = 00 Sum = 3! Column = n = 3 Digit = d = 3 Base = b = 0 0 0
Numbers, Numbers, Numbers Computers manipulate numbers by changing the state of switches Transistors = switches Each switch has two states This implies the use of the binary number system
Binary Base numbers are composed of possible digits (0 and ) Digits are associated with a power of based on its position A single binary digit is called a bit. For example 00 = x 4 + x 3 + 0 x + 0 x + x 0 = 6 + 8 + 0 + 0 + = 6 + 8 + = 5 0
Decimal and Binary Decimal Binary Decimal Binary 0 8 9 0 3 4 5 3 6 4 7 5
Decimal and Binary Decimal Binary Decimal Binary 0 0000 8 000 000 9 00 000 0 00 3 00 0 4 000 00 5 00 3 0 6 00 4 0 7 0 5
Convert from Decimal to Binary Convert 5 0 to Binary 5 0 = 5 = r = 6 r 0 6 = 3 r 0 3 = r = 0 r
Convert from Decimal to Binary Convert 5 0 to Binary 5 0 = 5 = r = 6 r 0 6 = 3 r 0 3 = r = 0 r = 00
What about other bases? Octal? Convert 35 0 to base 8: 35 8 = 9 r 3 9 8 = 3 r 5 3 8 = 0 r 3 So, 35 0 = 353 8
General Algorithm To convert from Decimal to another base: (Use division algorithm) Divide the given number by the base repeatedly, until the quotient becomes zero The resulting remainder in reverse order make up the number in the new base
What about base N to base M? How would we convert one base to another since we don t have formulas for that? Transition through decimal! Convert base N to base 0 Then, convert base 0 to base M
Hexadecimal Base 6 Represents digits 0 through 5 Contains the digits 0 through 9 and letters A through F Digit A is equivalent to 0 in decimal, B is, and so on
Decimal, Binary, and Hexadecimal Decimal Binary Hex Decimal Binary Hex 0 0000 8 000 000 9 00 000 0 00 3 00 0 4 000 00 5 00 3 0 6 00 4 0 7 0 5
Decimal, Binary, and Hexadecimal Decimal Binary Hex Decimal Binary Hex 0 0000 0 8 000 8 000 9 00 9 000 0 00 A 3 00 3 0 B 4 000 4 00 C 5 00 5 3 0 D 6 00 6 4 0 E 7 0 7 5 F
Hexadecimal Hex digits have a power of 6 associated with them. Example: Convert BD 6 to decimal: BD 6 = x 6 + B x 6 + D x 6 0 = 70 0 = x 6 + x 6 + 3 x 6 0 = 5 + 76 + 3
Hexadecimal Convert 589 0 to base 6: 589 6 = 36 r 3 36 6 = r 4 6 = 0 r ( D) Therefore, 589 0 = 4D 6
Binary to Hexadecimal Normally you would go from base n to base m by transitioning through decimal Remember: Convert base N to base 0 Then, convert base 0 to base M To make things even more convenient: 6 is a power of
Binary to Hexadecimal 6 is a power of 4, so we can simply group our binary digits by 4s and translate Example 00 00 0000 = 00 = 9 0 = 9 6 00 = 0 0 = A 6 0000 = 0 0 = 0 6 So, 00 00 0000 = 9A0 6
Ok you try. Convert 430 5 to decimal.. Convert 00 0 000 to decimal. 3. Convert # to hexadecimal. 4. Convert 35 0 to base 4 and octal.
Summary Notation Unless otherwise stated in a problem, the base of the number given will be in the subscript. Ex, 345 0 for decimal and A 6 for hex Tips and Tricks (things to watch out for) No digit in your answer should hold a value greater than or equal to the base you are working in. In binary, the first bit determines where the number is even or odd. When switching from a small base to a larger base, the amount of digits needed to represent the value will not increase; likewise, going from large to small, the number of digits needed to represent the value will not decrease.
It doesn t stop there ADDITIONS, AND SUBTRACTIONS
Binary Addition Let s add 3 + 6 In decimal, 3 + 6 = 9 But let s do it in binary: 0 + 00 We have to add column by column
Binary Addition 0 + 00 0 0 First column, + 0 = Second column, 0 + = Third column, + = X? = 0 must carry to next column! Fourth column, + 0 + = must carry to next column! 0
Binary Addition Let s check our answer! 0 + 00 00 Convert the answer and see what we get: 00 = 4 + 0 3 + 0 + + 0 = 6 + 0 + 0 + + = 9 0
Binary Subtraction In-class Demo Refer to Section.4. (Neveln)
Hex Addition In-class Demo We will need the chart again Refer to section.6. (Neveln) Decimal Hex Decimal Hex 0 0 8 8 9 9 0 A 3 3 B 4 4 C 5 5 3 D 6 6 4 E 7 7 5 F
Hex Subtraction In-class Demo We will need the chart again Refer to section.6. (Neveln) Decimal Hex Decimal Hex 0 0 8 8 9 9 0 A 3 3 B 4 4 C 5 5 3 D 6 6 4 E 7 7 5 F
And just because I know you are enjoying this so much FRACTIONS
Fractions in Other Bases In order to use floating point in computer computations, all fractions and powers must be in binary instead of decimal. Decimal fractions, of course, are our everyday standard. Ex,. 5 = + 0 0 = 5 000 = 8 + 5 0 3
Converting Fractions Suppose that we are given a fraction in another base. Use multiplicative process to do the conversion. Ex. We are given.333333 0, and we wish to convert it to a binary fraction.
Converting Fractions Ex. (cont.) We are given.333333 0, and we wish to convert it to a binary fraction. Let.d d d 3 represent the digits in our binary fraction. Let s use the equality:. 33333 = d + d + d 3 3 +
Converting Fractions Ex. (cont.) Let s use the equality:. 33333 = d + d Now solve. Begin by doubling both sides:. 66666 = d + d + d3 + d 3 + Note: The integer parts on both sides must agree. This implies that d = 0 Remove the integer portion and Repeat! 3 +
Converting Fractions Ex. (cont.) We now have. 66666 = d Double both sides again:.33333 = d + d 3 + d3 + d4 + + Note again the integer portion. This implies that d = Remove the integer portion and Repeat!
Converting Fractions Ex. (cont.) We now have. 33333 = d 3 + d4 + By continuing in this manner, you will see that: d 3 = 0, d 4 =, d 5 = 0, d 6 =, and so on So,.33333 0 =.0000
Converting Fractions Will this process work with other bases? Yes!! Convert.33333 0 to base 5 Set up equation:. 33333 = d? + d? + d 3? 3 +
Converting Fractions Will this process work with other bases? Yes!! Convert.33333 0 to base 5 Set up equation:. 33333 = d Now what? 5 + d 5 + d 3 5 3 + Multiply by the equation by 5 (instead of ) since we are going to base five then continue the process described in the prior example.
Converting Fractions.33333 = d 5 + d 5 + d3 5 3 + Multiply by 5:.66666 = d + d 5 + d3 5 + d = Remove the integer. 66666 = d 5 + d3 5 + d4 5 3 + Multiply by 5: 3.33333 = d + d 3 5 + d4 5 + d = 3
Converting Fractions.33333 = d 3 5 + d4 5 + d5 5 3 + Multiply by 5:.66666 = d 3 + d 4 d 3 = Remove the integer Continuing in this way d 4 = 3, d 5 =, d 6 = 3, and so on So, 5 + d5 5 +.33333 0 =.3333 5
ANY QUESTIONS?