### assignment expression

I have to do this for a practice assignment but i missed the class where it talked about it, can anyone help me?
Write an assignment expression to increase the value of the variable quantity by the value of the variable extra.

= is the assignment operator.
+ is the addition operator.
+= is a compound operator of equal and plus so that a += b is a = a + b

So you need something like:
 ``123`` ``````quantity += extra; //prefered //or quantity = quantity + extra;``````
oh ok and then its asking to write a bit-wise expression to return twice the value of the integer variable quantity.
If you shift to the left you multiply by 2. If you shift to right you divide by 2. If you look at binary numbers you will tell easily why.

0001 = 1
0010 = 2
0100 = 4
1000 = 8
0000 = 0 //if it was more than 1 byte it would be 0001 0000

now lets look at it backwards:
1000 = 8
0100 = 4
0010 = 2
0001 = 1
0000 = 0
but how do I write that in a bit wise expression?
Same way you would addition but with the bitwise shift.

http://www.cplusplus.com/doc/tutorial/operators/
 ``123`` ``````quantity <<= 1; //or quantity = quantity << 1;``````
thank you so much
Topic archived. No new replies allowed.