cs240 Exam 1 Review Sheet

cs240 Exam 1 Review Sheet - Math Section Range = Base ^ N...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Math Section Range = Base ^ N i.e. 16 bits (bits are base 2) has range of 2^16 = 64K 2^32 4G (billion) Binary Multiplication is shifting 110101 × 1001 110101 +110101000 Converting from Base to Decimal 13754 base8 to Decimal 8 4 × 1 + 8 3 × 3 + 8 2 × 7 + 8 1 × 5 + 8 0 (1) × 4 = 6124 Other Method Multiplying 1 ×8 = 8 + 3 = 11 11 ×8 = 88 + 7 = 95 95 × 8 = 760 + 5 = 765 765 × 8 = 6120 + 4 = 6124 Converting from Decimal to Base 6124 to Base5 Algorithmic Division 6124 / 5 = 1224 r 4 1224 / 5 = 244 r 4 244 / 5 = 48 r 4 48 / 5 = 9 r 3 9 / 5 = 1 r 4 1 / 5 = 0 r 1 =143444 Brute Force – divide by largest 5^n 6124 / 3125(or 5^5)= 1 2999 / 625(or 5^4) = 4 499 / 625(or 5^3) = 3 124 / 25(or 5^2) = 4 24 / 5( or 5^1) = 4 4 / 5^0 = 4 143444 base5 Related Bases Bases 2, 4, 8, 16… are related 0011 010 1 1101 1000 = 35D8 Hex, 32730 Octal, 113120 base4 Multiplication and Adding Hex (other bases’ principle is the same) F +F = 1E (15 + 15 = 30 – 16 (Next Place) = 14 (1E, 1(16) + 14)) F × F = E1 (15 × 15 =225 / 16 = 14 r1 remainder becomes 1s place, so E 1) Representing Numerical Data Binary Coded Decimal - BCD: represents each digit with 4 bits. i.e. 8 bit storage range would be 0 – 99, 99 =1001 1001, 50 =0101 0000, 8=0000 1000 Drawbacks are: - BCD has a range that is less than conventional binary representation -Calculations in BCD are more difficult for the computer thus slower Signed Integer Representation Changing the leftmost digit in Binary to a 0(+) or 1(-). This divides the bit range in half effectively, and creates the double zero problem. In addition, if the signs don’t agree, the result will be incorrect. i.e. 0…0100(4) + 1…0010(-2) = 1…0110 (-6) Overflow – when the result does not fit into the fixed # of bits for a result. If both inputs to an addition have the same sign and the output sign is different overflow has occurred. One’s Complement: -127 to -0 (10000000 to 11111111) & 0 to 127 (0 to 01111111) Add two #s 01101010 = 106 +11111101 = -2 (+2 is 00000010, change 0’s to 1’s) 101100111 (carry over take the leftmost 1 and add it back) +1 01101000 = 104 Two’s Complement : -128 to -1 (10000000 to 1…1) & 0 to 127 (0 to 01111111) Positive # in One’s and Two’s complement are equal Negative # in two’s complement is found by writing the # in binary, inverting the digits and adding 1 i.e. Find -28 in Two’s 0001 1100 28 Binary 1110 0011 Swap 1s & 0s +1 add 1 1110 0100 = -28 in Two’s Converting neg. two’s complement # is, swap 1s & 0s convert to decimal add 1. Other complements – take each digit and subtract it from the # complement, i.e. 16s complement of 4C4D = F-2 F-C F-4 F-D or D3B2 Little Man Computer Take input IN 901 Print Output OU T 902 Store num to Address ST O 3xx Load num from Address LD A 5xx Add num in Address to accum AD D 1xx Sub num in Address from accum SU B 2xx Branch to address unconditionally BR 6xx Branch to address if accum value is 0 BR Z 7xx Branch if accum value is positive (0 is positive) BR P 8xx Halt program HL T 000 Place data in next available box DA T Example LMC Programs Multiply any 2 user #s 1. IN 2. STO 99 3. IN 4. STO 98 5. SUB 90 //Prevent over adding by 1 6. STO 97 7. LDA 98 8. ADD 99 9. STO 98 10. LDA 97 11. SUB 90 12.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern