Bitwise Operations

...

What will most of the work you do in C, C++, Java, or C# be?
Most of the work you do in C, C++, Java, or C# will be manipulating integers and strings.

What can happen if you assign an integer number that requires more than 32 or 64 bits to represent its value in C/C++ on 32-bit or 64-bit machines?
If you assign an integer number that requires more than 32 or 64 bits to represent its value in C/C++ on 32-bit or 64-bit machines, the most significant bits (the overflow) will be lost.

What can you use to recover the high-order bits after a multiplication if you need them?
If you need the high-order bits after a multiplication, you can use assembly code.

Bitwise Shift Left: <<

What does bitwise shift left do to a value?
Bitwise shift left shifts the value's bits into higher places and adds zeros in the vacated lower places.

Example of bitwise shift left

3 << 0 == 3 or 0011
3 << 1 == 6 or 0110
3 << 2 == 12 or 1100

What does 1 << n do?
1 << n pushes 1 and then an n number of zeros.

What is the value of k << n?
The value of k << n is .

What does k << 0 equal for any n and k?
k << 0 equals k for any n and k

What is the maximum number of bits you can left shift by?
The maximum number of bits you can shift left by is as many as you want.

Can you left shift by a negative number?
No, you can't left shift by a negative number.

What does C++ overload the left shift operator for?
C++ overloads the left shift operator for iostream output.

What do you have to be careful of when using the left shift operator in an iostream expression and why?
When using the left shift operator in an iostream expression, you have to be careful to put parentheses around the bitwise operation because the iostream output has higher precedence over bitwise operations like left shift.

Bitwise Right Shift: >>

What does bitwise right shift do to a value?
Bitwise right shift shifts the value's bits into lower places and adds zeros in the vacated higher places.

...