Following is mainly a complement to Barry's answer, that clearly explains the rules for left and right shifting.
At least fo C++11, the integral promotion of a bool gives 0 for false
and 1 for true
: 4.5 Integral promotions [conv.prom] § 6
A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one.
So in original examples, b
, d
, f
and h
will all get a 0 value, a
and c
both get a 8
value: only perfectly defined behaviour until here.
But e
and g
will receive the unsigned value 0x80000000
, so it would be fine if you affected it to an unsigned int variable, but you are using signed 32 bits integers. So you get an integral conversion: 4.7 Integral conversions [conv.integral] §3
If the destination type is signed, the value is unchanged if it can be represented in the destination type; otherwise, the value is implementation-defined.
And unsigned 0x80000000 is not representable in a signed 64 bits integer so the result is implementation defined for e
and g
.