xHarbour Reference Documentation > Operator Reference |
Right-shift operator (binary): shifts bits to the right.
<nNumber1> >> <nNumber2>
The >> operator accesses individual bits in the left operand and shifts them to the right as many times as specified with the right operand. Both operands are always treated as integer values. If an operand has a decimal fraction, it is truncated prior to the operation.
A shift operation involves all bits of the left operand. When the bits are shifted one place to the right, the lowest bit is discarded and the highest bit is set to 0. A numeric value has 32 bits on a 32 bit operating system.
Shifting a nonnegative value to the right is equivalent with dividing <nNumber1> by 2 raised to the power of <nNumber2>.
See also: | <<, HB_BitShift() |
Category: | Bitwise operators , Operators , xHarbour extensions |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example shifts the bits of the value 52 two places to // the right so the value becomes 13. PROCEDURE Main nValue := 52 // binary: 00110100 ? nValue >> 2 // binary: 00001101 (value = 13) ? 52 / 2 ˆ 2 // result: 13 RETURN
http://www.xHarbour.com