Page 1 of 1 1
Topic Options
#110118 - 2003-12-11 05:24 PM Need bitwise negation operator
Howard Bullock Offline
KiX Supporter

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
To perform bitwise operation like | and & where one needs to turn off a bit we need a bitwise negation operator.

Turn on bit: $x = $x | 64
Turn off bit: $x = $x & ~64

In this example "~" performs a bitwise negation so that performing a bitwise "and" of bits only turn off the bit representing 64.
Home page:

#110119 - 2003-12-12 10:12 AM Re: Need bitwise negation operator
Richard H. Administrator Offline

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
See my comments in the original thread re word size.

While you are waiting, here is a UDF NOT function:
Function funNot($dValue,Optional $iWordSize)

; Cast result to correct type

; Calculate the value of all bits set
If Val($iWordSize) $iWordSize=Val($iWordSize) Else $iWordSize=16 EndIf
While $iWordSize $iWordSize=$iWordSize-1 $funNot=$funNot*2 Loop


To use:
Turn off bit: $x = $x & funNot(64)

If the size of the mask is important, supply the optional word size:
"The maximum value of an 8 bit word (byte) is: " funNot(0,8)

I've left the default word size set as 16 bits.

Page 1 of 1 1

Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 170 anonymous users online.
Newest Members
dimi575, Drecksnacken, Nlill, webtools321, multiman
17734 Registered Users

Generated in 0.05 seconds in which 0.032 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google: