xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_BitReset()

Sets a bit in a numeric integer value to 0.

Syntax

HB_BitReset( <nInteger>, <nPosition> ) --> nResult

Arguments

<nInteger>
This is a numeric integer value.
<nPosition>
This numeric parameter specifies the position of the bit to set to 0. The least significant bit has position zero, so that the range for <nPosition> is 0 to 31 on a 32-bit operating system.

Return

The function returns the integer number where the specified bit is set to 0.

Description

Function HB_BitReset() sets a single bit of a numeric integer to 0. If the bit at position <nPosition> is not set in <nInteger>, the result has the same value, otherwise its value is different.

Info

See also:HB_BitIsSet(), HB_BitSet(), HB_BitShift()
Category: Bitwise functions , xHarbour extensions
Source:rtl\hbBitf.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example displays the result of HB_BitReset() with the
// help of a user defined function Num2Bit(). The bit sequence
// and the numeric value resulting from the operation is shown.

   PROCEDURE Main
      LOCAL nInt := 4567
      LOCAL n, i

      ? "Original :", " ", Num2Bit( nInt ), LTrim(Str(nInt))
      ?
      FOR i:= 0 TO 7
         n :=  HB_BitReset( nInt, i )
         ? "Reset Bit:", LTrim(Str(i)), Num2Bit( n ), LTrim(Str(n))
      NEXT

      ** output
      // Original :   11010111 4567

      // Reset Bit: 0 11010110 4566
      // Reset Bit: 1 11010101 4565
      // Reset Bit: 2 11010011 4563
      // Reset Bit: 3 11010111 4567
      // Reset Bit: 4 11000111 4551
      // Reset Bit: 5 11010111 4567
      // Reset Bit: 6 10010111 4503
      // Reset Bit: 7 01010111 4439
   RETURN


   FUNCTION Num2Bit( nNumber )
      LOCAL nInt := Int( nNumber )
      LOCAL nLen := 7
      LOCAL cBin := Replicate( "0", nLen+1 )
      LOCAL nPos

      FOR nPos := 0 TO nLen
         IF HB_BitIsSet( nInt, nPos )
            cBin[ nLen-nPos+1 ] := "1"
         ENDIF
      NEXT
   RETURN cBin

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