V
vbano
I need bitwise functions for a spreadsheet (shift, OR, XOR, etc). Is there a
way to do this in Excel for example?
way to do this in Excel for example?
Mike H said:Excel has an OR function and [...] for XOR you can use.
=NOT(A1)+NOT(B1)=1
I have no idea what 'shift' or etc mean in this context
I said:Ostensibly, shift left and right can be accomplish by multiplying and
dividing by 2, assuming the OP does not want circular shifts.
However, that will not shift bits into and out the sign bit. I believe
that
handling that will also cover the boundary condition the can result in an
overflow error when "shifting left".
binAND(12,10) is 8 because 12 is the binary 1100, 10 is the binary 1010,
and 8 is the binary 1000.
Joe User said:Mike H said:Excel has an OR function and [...] for XOR you can use.
=NOT(A1)+NOT(B1)=1
Excel functions are boolean operations, not bitwise operations. Compare
the
difference between:
=--AND(12,10)
=bitAND(12,10)
Function bitAND(a as long, b as long) as long
bitAND = a AND b
End Function
Presumably, the OP wants the bitAND result.
For Mike's edification, the difference is: a bitwise function operates on
the individual truth value (0 or 1) of individual bits, whereas a boolean
function operates on the truth value (zero or non-zero) of the entire
value.
binAND(12,10) is 8 because 12 is the binary 1100, 10 is the binary 1010,
and
8 is the binary 1000.
I have no idea what 'shift' or etc mean in this context
Ostensibly, shift left and right can be accomplish by multiplying and
dividing by 2, assuming the OP does not want circular shifts.
However, that will not shift bits into and out the sign bit. I believe
that
handling that will also cover the boundary condition the can result in an
overflow error when "shifting left".
----- original message -----
Mike H said:Excel has an OR function and VBA has both OR and XOR but the latter is
not
included as a worksheet function but for XOR you can use.
=NOT(A1)+NOT(B1)=1
another XOR
=(A1<>0)+(B1<>0)=1
I have no idea what 'shift' or etc mean in this context
--
Mike
When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.