Positional notation Ch.. /continued Conversions between Decimal and Binary Binary to Decimal - use the definition of a number in a positional number system with base - evaluate the definition formula using decimal arithmetic 54 position = corresponding power of 5 4 = + + + + + = 4 (decimal) d 5 d 4 d d d d Decimal to Binary - repeatedly divide by - remainder is the next digit - binary number is developed right to left 7 86 86 4 4 5 5 CSE 5 Week. May 5, 4 page
What is going on in the repeated division by? 4 5 5 5 4 4 (decimal) = + + + + + 4 produces a quotient of, with a remainder of 4 4 = + + + + + 4 (decimal) = + + + + produces a quotient of, with a remainder of = + + + + (decimal) = + + + produces a quotient of 5, with a remainder of = + + + 5 (decimal) = + + 5 produces a quotient of, with a remainder of 5 = + + (decimal) = + produces a quotient of, with a remainder of = + (decimal) = produces a quotient of, with a remainder of = + CSE 5 Week. May 5, 4 page
Generalization: Conversions between Decimal and base b base b to Decimal - use the definition of a number in a positional number system with base b - evaluate the definition formula using decimal arithmetic Decimal to base b - repeatedly divide by b - remainder is the next digit - base b number is developed right to left Conversions between Binary and Octal/Hexadecimal Binary to Octal - group bits into threes, right to left - convert each such group to an octal digit = = 7 (octal) Binary to Hexadecimal - group bits into fours, right to left - convert each such group to a hexadecimal digit = = CB (hexadecimal) CSE 5 Week. May 5, 4 page
Octal to Binary - convert each octal digit to a three-bit binary representation 75 = = (binary) Hexadecimal to Binary - convert each octal digit to a four-bit binary representation AF = = (binary) You need the following tables in the above conversion processes: (These can easily be reconstructed in the margins of a test paper when needed) Binary Octal Binary Hexadecimal Octal Binary Hex Binary Digits Digits 8 9 () A () B 4 4 () C 5 5 () D 6 6 (4) E 7 7 (5) F CSE 5 Week. May 5, 4 page 4
What about converting between Octal and Hexadecimal? Octal to Hexadecimal: Convert Octal to Binary and then convert Binary to Hexadecimal. Hexadecimal to Octal: Convert Hexadecimal to Binary and then convert Binary to Octal. CSE 5 Week. May 5, 4 page 5
Chapter Data Representation Data and computers Ch.. everything inside a computer is stored as patterns of s and s. numbers, text, audio, video, images, graphics, etc. how do you convert it to s and s. how do you store the s and s efficiently. Representing Numeric data Ch.. Representing Natural numbers with a finite number of digits General Property Number of digits Min Max n n b s: b=, n= to 999 b=, n= to (equivalent to to 7, in decimal) b=8, n= to 777 (equivalent to to 5, in decimal) b=6, n= to FFF (equivalent to to, in decimal) CSE 5 Week. May 5, 4 page 6
Representing Negative Number (Integers) Basic Definition an integer is a number which has no fractional part s: + -67 Integers (Signed, natural numbers) previously: unsigned numbers only, i.e. natural numbers need mechanism to represent both positive and negative numbers two schemes: ) sign-magnitude, ) complementary representation Sign-Magnitude in binary: sign: left-most bit ( = positive, = negative) magnitude: remaining bits : (using 6-bit sign-magnitude representation) +5 = -5 = Ranges Binary Unsigned Sign-Magnitude (Natural Number) (Integer) Number of bits Min Max Min Max + 7 + 4 5 7 +7 5 5 +5 6 6 + etc. n n n n CSE 5 Week. May 5, 4 page 7
Difficulties with Sign-Magnitude two representations for zero + = - = arithmetic is awkward, especially subtraction Complementary Representation positive numbers are represented by their corresponding natural numbers negative numbers are represented as (very) large natural numbers subtraction reduces to addition negative numbers: x b n x : Let b and n Positive Negative numbers numbers (+) (+) 99 (-) (+) 98 (-) (+) 97 (-)...... (+49) 49 5 (-49) 5 (-5) CSE 5 Week. May 5, 4 page 8
Visualization: -49-5 +49 5 5 49 99 - + + 5 98 99 49-5 - - + + + +49 CSE 5 Week. May 5, 4 page 9