xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

SetBit()

Sets one or more bits of a numeric integer value to 1.

Syntax

SetBit( <nInteger>|<cHex>, [<nBitPos,...>]) --> nInteger

Arguments

<nInteger>
A numeric 32-bit integer value can be specified as first parameter.
<cHex>
Alternatively, the integer can be passed as a hex-encoded character string (see NumToHex()).
<nBitPos>
The positions of the bits to set are defined as a comma separated list of numeric integer values. The range for <nBitPos> is 1 to 32.

Return

The function returns a numeric integer value with the bits at the specified positions set to 1.

Info

See also:IsBit(), NumAND(), NumNOT(), NumOR(), NumXOR()
Category: CT:NumBits , Bitwise functions , Numbers and Bits
Source:ct\bit2.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example displays results of SetBit() along with the
// binary representation of the numbers.

   PROCEDURE Main
      ? NtoC( 0, 2, 8, "0" )         // result: 00000000

      ? n := SetBit( 0, 1, 7 )       // result:    65.00
      ? NtoC( n, 2, 8, "0" )         // result: 01000001

      ? n := SetBit( 0, 2, 4, 6 )    // result:    42.00
      ? NtoC( n, 2, 8, "0" )         // result: 00101010
   RETURN

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