Presentation on theme: "Introduction Were learnin bout numberrrrs! O_O >_< ^_^"— Presentation transcript:
Introduction Were learnin bout numberrrrs! O_O >_< ^_^
Okay, so this is how you add… The general premise of addition is adding numbers and carrying when necessary. Carrying is the important part Like, so important that you could fail epically if you dont. Just wait.
Adding some more. Start on the right side as normal 1+1 = 2; since this cannot be expressed with one digit, we carry a 1 (just like normal addition) 1+0+0=1 0+1 = 1 1+1=2, carry again 1+0 =
Subtracting… Its like James and me. I borrow from him all the time. The difference is that I give him some back, sometimes. And apparently this pays back as well.
Subtracting some more. Start on the right side as normal 0<1, so borrow =1 (in binary) Pay back 1 1+1=10, 1 < 10, so borrow = 1 Pay back = (10) 1+ (10) 1 1+
Addition of Hex Values Hex is base 16, uses 0-9 and A-F. Same process as any other base: carry over when the current column capacity has been exceeded.
Hex Addition 5+D = 5+14 = = 16+3 = (10 + 3) 16 This means we carry a 1 into the next column A+F+1= = = = (10 + A) This means we carry a 1 A5 +FD A3
Integer Representation A byte has 8 bits, which allows for 256 variations (different numbers) [2 8 ] If we want positive and negative though, we use the Most Significant Bit (MSB) to determine sign (1 = negative, 0 = positive) This lets us go from -127 to 127 Notice a number is lost in the range (+/- 0), meaning only 255 distinct numbers possible
Questions!? What range of numbers can be gotten from 6 bits?(unsigned) What is unsigned? Signed? unsigned? Signed?
Representing Negative Numbers Using Two complement Another method involves setting the MSB to be -128 and making the rest positive to get a range of negative numbers base 2 = base 2 = -127 Etc. To go from positive to negative, just flip the bits and add 1 base 2: 8 base 10 = base 10 = = base 2
Practice Convert to Twos Complement:
Representing Real Numbers Two ways of representing: – Fixed point or floating point – Fractional and Whole parts separated by a Radix point. With fixed point between bits 3 and 4, making bits 3, 2, and 1 negative, max range is from to Everything after the decimal place gains a negative exponent 0.1 base 2 = 2 -1, base 2 = 2 -3
(cont.) This can be created with twos complement, which places the fixed point between 4 and 5. Fixed point just doesnt have a lot of range with a given set of bits.
Floating Point Representation Until recently, floating point has been a pain. IEEE 734 created a standard for them. However, its hard and junk apparently, so they wont tell us about it. BUT. They explicitly reference wikipedia. Such a terrible source. The mantissa is basically the decimalised version of the number.
Floating Point Algorithmic example Convert 12.5 to normalised binary format. 1.Convert 12.5 to binary: Move the point four to the left: (mantissa) 3.That four becomes the exponent, write it in binary: Write the number as mantissa * 2 exponent *
Advantages of Integer and Floating Point Integers can be stored accurately Floating point allows more numbers to be represented Floating points allows fractional values (kinda ties in with the above)
Truncation, Underflow, and Overflow Errors Truncation cuts off anything after the radix point. Happens when you try to put a decimal/real number in an integer slot. Overflow basically is trying to put a number that is too big into a slot… like when you enter into something. This can also occur when the mantissa of floating point or exponent are to large to be represented in the number of bits. Underflow is when a number to be stored is too small. The underflow case for floating point can be the same as the overflow case if the exponent is too large to be represented in both cases.