| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Sets a bit in a numeric integer value to 0.
HB_BitReset( <nInteger>, <nPosition> ) --> nResult
The function returns the integer number where the specified bit is set to 0.
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.
| See also: | HB_BitIsSet(), HB_BitSet(), HB_BitShift() |
| Category: | Bitwise functions , xHarbour extensions |
| Source: | rtl\hbBitf.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com