binary logic operators

  • Thread starter Thread starter Kevin Brown
  • Start date Start date
K

Kevin Brown

I'm trying to do some simple logic operations; I've used
the limited functions DEC2BIN for converting decimal
number to binary format, now need to operate on the binary
results, e.g. convert to 2's complement, simple AND, OR
type functions...anyone have ideas?
 
Kevin Brown said:
I'm trying to do some simple logic operations; I've used
the limited functions DEC2BIN for converting decimal
number to binary format, now need to operate on the binary
results, e.g. convert to 2's complement, simple AND, OR
type functions...anyone have ideas?

You don't need to convert integers to binary (text) representation. See

http://groups.google.com/[email protected]
 
If you mean bit-wise AND and OR, etc, you need VBA functions. The worksheet functions are
logical AND, logical OR, not bitwise. VBA's AND, OR, and NOT are bit-wise operators.

The code is straight-forward. The arguments are ordinary decimal numbers, not the text result of
DEC2BIN.

Function BitAnd(X As Long, Y As Long)
BitAnd = X And Y
End Function

Function BitOR(X As Long, Y As Long)
BitOR = X Or Y
End Function

My memory is fading, but isn't the 2's complement of X equal to -X + 1? If so, you can implement
that with a worksheet formula without converting to binary.
 
Back
Top