xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

>>

Right-shift operator (binary): shifts bits to the right.

Syntax

<nNumber1> >> <nNumber2>

Arguments

<nNumber1>
<nNumber1> is a numeric value whose bits are shifted to the right.
<nNumber2>
<nNumber2> is a number indicating how many places the bits are shifted to the right.

Description

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>.

Info

See also:<<, HB_BitShift()
Category: Bitwise operators , Operators , xHarbour extensions
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe