October 18, 1999 - The Bitwise Left Shift Operator
October 18, 1999 The Bitwise Left Shift Operator Tips: October 1999
Yehuda Shiran, Ph.D.
|
Name Decimal Hex Binary Op1 179 0xB3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 Op1 716 0x2CC 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 0
Left shifting a number n places is the same as multiplying it by 2n. Left shifting preserves the operand's sign and thus this rule applies to negative numbers as well. Normally, you would not multiply a number by left shifting it, because it is not clear to the reader. You would probably use it only when the performance is a critical factor.