Why to use & 0xff when bitshifting.?

And sometimes you need to promote to a "higher" type inside an expression even though the final result will fit into 16 bits.

@Montmorency, we should use auto (post #10) and casting from the original post is unnecessary (argued repeatedly).

I wonder what happens when a newbie blindly accepts both of your absolutes?

Montmorency:
The point is that you have to ... strive to use casts it only when they are necessary.

No, we don't.

If a typecast is unnecessary but we include it then no harm done (other than to offend your sensibilities).

If a typecast was necessary and we included it then good on us. Even if what we did was accidentally correct it is still correct.

MorganS:
And sometimes you need to promote to a "higher" type inside an expression even though the final result will fit into 16 bits.

Exactly. Also, that classic newbie question that has been asked on the Net a gazillion times already: "int a = 1, b = 2; double c = a/b; How come I don't get 0.5 in c?"

As you mentioned yourself previously, it is not just a question of "correctness". It is a question of good programming practices, that cover not only correctness, bit also readability and maintainability of the code.

You can stuff a program choke full of "magic constants" and still make it correct. Nevertheless, "magic constants" is a bad programming practice. "Correctness" of the program does not redeem them in any way.

Montmorency:
You can stuff a program choke full of "magic constants" and still make it correct.

Wow. You really do struggle staying on topic. (I do wonder if that is purposeful.)

In any case, I won't be wasting anymore of my time.

If @jmusther wants more details they only have to ask.

Wow. I never thought anybody would perceive a simple and appropriate analogy as an attempt to deviate from the topic.

The quote was meant as a single simple example to help you understand.