xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

<<

Left-shift operator (binary): shifts bits to the left.

Syntax

<nNumber1> << <nNumber2>

Arguments

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

Description

The << operator accesses individual bits in the left operand and shifts them to the left 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 left, the highest bit is discarded and the lowest bit is set to 0. A numeric value has 32 bits on a 32 bit operating system.

Shifting a value to the left is equivalent with multiplying <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 left so the value becomes 208.

   PROCEDURE Main
      nValue := 52            // binary: 00110100
      ? nValue << 2           // binary: 11010000 (value = 208)

      ? 52 * 2 ˆ 2            // result: 208
   RETURN

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