SwapBit
Result = SwapBit(Value, BitNo)
 
Parameters:

    Value = An integer value
    BitNo = The bit you want to swap (0 = least significant bit)
Returns:

    Result
 

      SwapBit swaps a specified bit of a given value, ie. if the bit is set(1) SwapBit clears it, if the bit is cleared SwapBit sets it. Bits range between 0 and 31. Where 0 is the least significant bit (LSB), 31 is the most significant bit (MSB).




Mini Tutorial:


      Showing the effect of SwapBit

  
; Swaps the bits 0 to 7 of the value 170 and
; display only these 8 bits using the Right$ function
  For i = 0 To 7
     Print Right$(Bin$(SwapBit(170,i)),8)
  Next i
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  



This example would output.

  
  10101011
  10101000
  10101110
  10100010
  10111010
  10001010
  11101010
  00101010
  


 
Related Info: And | ClearBit | Or | SetBit | TestBit | Xor :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com