Hi, I have a function in VB6 like this:

tot = CLng(tot Xor Not lngdata)

I'd like to do the same in c++, but I can't get the same results...

I've tried like this:

tot = (int)((-1) * (tot ^ lngdata) );

But I don't get exactly the same results....
Can anyone advise me why the above does not work as expected?

Many thanks in advance!

9 Years
Discussion Span
Last Post by ArkM

Well read literally, you have tot = CLng( tot ^ !lngdata) But is XOR-NOT is some new operator which is the logical inverse of XOR (like NAND is to AND), then perhaps one of these

tot = CLng( !tot ^ !lngdata)
tot = CLng( !(tot ^ lngdata) )

Post a truth-table if you're still stuck.


The problem is that with

tot ^= !lngdata;

if lngdata is 0 in VB I get -1 and in c++ I get 1

if lngdata is 39942 in VB I get -39943 and in c++ I get 0...



I've forgotten that in c++ the not operator is implemented with "~"

so the right code is:

tot = (tot ^ ~lngdata);

Many thanks anyway!


I've forgotten that in c++ the not operator is implemented with "~"

Just a little bit extra info: In C++ you've actually two NOT-operators (this does also apply to the AND and OR operators): you've the bitwise NOT-operator ~ and you also have the logical NOT-operator ! :) ...

You use the logical NOT-operator if you expect an expression to be true or false , the bitwise NOT is just wrapping all the bits of it's operand (1 becomes 0 and 0 becomes 1)
The NOT operators in C++ are both unary operators, which means that they both work with one operand.

Votes + Comments
nice clarification in this discussion!

Of course, operator ~. What's a shame :( Sorry.

Votes + Comments
Never mind, that's because you're used to solve the most sophisticated problems :P
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.