1Expressions9/5/20072Opening Discussion■Do you have any questions about the quiz?■Solutions to the interclass problem.3Multiplication■To multiply two binary numbers do standard long multiplication. Just remember when you are adding that you are adding binary numbers.■Note that adding more than two binary numbers can get tricky. It can result in carrying operations you have never done by hand in decimal.4Binary Fractions■If the digits in binary start with one and move to larger powers of two moving to the left, what happens if you put in a “binary point” and move to the right?■Numbers that have a fixed number of bits with a point at a selected position are called fixed point numbers. These were popular before floating point accelerators became common, but now they are only used on specialty hardware with low end chips.5Floating Point Numbers■Numbers that can have fractional values are represented with floating point numbers on virtually all modern machines.■Floating point numbers are basically like scientific notation in binary.v=(-1)s * (1+frac) * 2(exp-bias)■Single precision numbers use one bit for the sign, 8 for the exponent, 23 for the fractional part, and have a bias of 127.■Double precision uses one bit for sign, 11 for exponent, 52 for fraction, and has a bias of 1023.6Limitations of FP■Floating point numbers are not actually the real numbers you know from math even though we often use them that way.■They have limitations because of the fixed number of bits.■Some of the math properties you are used to for numbers don't actually hold for floating point numbers.■Example: (a+b)+c=a+(b+c)Try this with a, b, and c as floats and make a=1e7, b=-1e7, c=0.01.■You also have to be careful of things like subtracting two numbers that are almost equal.7Expressions in C■Types of expressionsPrimary – one operand, no operator➔Names, literals, and parenthesesPostfix – one operand followed by an operator➔Function calls, increment, and decrementPrefix – one operand (must be a variable) preceded by an operator➔Increment and decrementUnary – one general operand preceded by an operator➔sizeof, +/-, type castBinary – Two operands with an operator between them➔This is the most common form. It is what you are used to from math but there are some interesting operators in C you won't see in math. Includes assignment.Ternary – operator that takes three arguments➔We'll talk about this one later in the semester.8Precedence and Associativity■Different operators take precedence over others. There is a table at the front of your book that lists precedence. Some make sense (* before +). Some are C specific.■When in doubt put in parentheses to make it clear.■Associativity is the direction in which operators of the same precedence are considered.9Side Effects■Some expressions have side effects.■All expressions have a value associated with them. I'll sometimes call it their return value.■An expression that has side effects not only returns a value, it also changes something else in the memory of the machine.■Side effects are very important. Good programming form doesn't place side effects in places where most people don't expect them.■Doing so makes code that is very hard for other people to read or debug.■Examples: ++, --, =.10Minute Essay■Right now are you considering signing up for PAD2 next semester?■There is an ACM meeting this afternoon at 5:00 in HAS 329. You should consider coming if you are free.■Interclass Problem – Write code that includes expressions involving five different operators. Print the values of those expressions. At least one of the operators must be
View Full Document