binary logic operators

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?
 
H

Harlan Grove

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]
 
M

Myrna Larson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top