3.0 - Bitwise Operator's
- Bitwise operators perform operations on bits
- The operand type shall be integral
- Return type is integral value
- Bitwise Shift:
Syntax:
Left Shift : shift-expression << additive-expression
(left operand) (right operand)
Right Shift : shift-expression >> additive-expression
(left operand) (right operand)
- Bitwise - Left Shift:
'Value' << 'Bits Count'
- Value : Is shift-expression on which bit shifting effect to be applied
- Bits count : Is additive-expression, by how many bit(s) the given “Value” to be shifted
- Bitwise - Right Shift:
'Value' >> 'Bits Count'
- Value : Is shift-expression on which bit shifting effect to be applied
- Bits count : Is additive-expression, by how many bit(s) the given “Value” to be shifted
Bitwise – Right Shift – Signed Valued
"Signed Value' >> 'Bits Count'
- Same operation as mentioned in previous slide.
- But the sign bits gets propagated.
Bitwise – Shift
- Each of the operands shall have integer type
- The integer promotions are performed on each of the operands
- If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behaviour is undefined
- Left shift (<<) operator : If left operand has a signed type and non-negative value, and (left_operand * (2^n)) is representable in the result type, then that is the resulting value; otherwise, the behaviour is undefined
- The left operand of a comma operator is evaluated as a void expression (result discarded)
- Then the right operand is evaluated; the result has its type and value
- Comma acts as separator (not an operator) in following cases :-
– Lists of initialises (variable declarations)
– But, can be used with parentheses as function arguments such as :
– foo ((x = 2, x + 3)); // final value of argument is 5
...
Post a Comment