シフト演算子>>
または<<
:
オペランドは のintegral
タイプまたは対象である必要がありますintegral promotion
。
右のオペランドが負の値であるか、左のオペランドのビットより大きい場合Undefined behaviour
左オペランドが負>>
の場合、それはimplementation defiend
andです<<
undefined behaviour
K&R Appendix-A より引用
The shift operators << and >> group left-to-right. For both operators,
each operand must be integral, and is subject to integral the promotions.
The type of the result is that of the promoted left operand.
The result is undefined if the right operand is negative,
or greater than or equal to the number of bits in the left expression's type.
shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
The value of E1<<E2 is E1 (interpreted as a bit pattern) left-shifted E2 bits;
in the absence of overflow, this is equivalent to multiplication by 2. The value
of E1>>E2 is E1 right-shifted E2 bit positions. The right shift is equivalent to division
by 2. if E1 is unsigned or it has a non-negative value; otherwise the result is
implementation-defined.