ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

NOT function wrong behaviour

Solved!
Go to solution

HI everyone,

I have been trying to get the opposite value of a binary channel using NOT function and i don't get the right values.

i'm extracting bits from a word with GetB

then i have to use CTNV to clean the NOVALUE data because of the malfunction of the GetB (already corrected for Diadem 2012 but not for my 10.2)

and at last i will like to get the invert value so: 0 will be 1 and 1 will be 0

These is the code that i'm using and the results:

 

Call ChnCalculate("Ch(""[1]/CHFS Bit 0"")=GetB(Ch(""[1]/CH 2 CHFS""),0)")

Call ChnCalculate("Ch(""[1]/CHFS Bit 0"")=Ch(""[1]/CHFS Bit 0"")+CTNV(Ch(""[1]/CHFS Bit 0"")>1)")

Call ChnCalculate("Ch(""[1]/CHFS Bit 0_a"")=NOT (Ch(""[1]/CHFS Bit 0""))")

 

Results:

1 = -2

0 = -1

 

i can correct with an offset but will be more time for process the data... and if is a malfunction like in GetB is important to correct too...

I'm doing something wrong or is a real malfunction ?

 

Thanks in advance

 

Rafael

 

0 Kudos
Message 1 of 3
(4,842 Views)
Solution
Accepted by caracasnet

Hello Rafael,

 

the problem here is the assumtion that true is equal 1.

This is not true. In VB true is -1 and in general there is only one real assumtion for bool true which is "true is not false".

 

MsgBox CInt(true)

==> -1

MsgBox CInt(false)

==> 0

 

So after changing your formula to

Call ChnCalculate("Ch(""[1]/CHFS Bit 0_a"")=NOT CBool((Ch(""[1]/CHFS Bit 0"")))")

 Your results will go to 0 and -1 which is true and false.

 

But now your case. Why does NOT 1 result in -2.

Thats easy because its a logical operation to every single bit in the integer number

 1 = 00000000000000000000000000000001
-2 = 11111111111111111111111111111110

 

You can validate this with the Programmer View of Microsfts calc.exe

NOT 1 also results in -2

 

So everything is working well. Even if its a little bit unexpected.

Call ChnCalculate("Ch(""[1]/CHFS Bit 0_a"")=Abs(NOT CBool((Ch(""[1]/CHFS Bit 0""))))")

 Results in what you want.

 

greetings from rainy germany

Andreas

 

 

Message 2 of 3
(4,832 Views)

I love this Forum....

 

THANKS a lot for the explanation, i understood perfect, and thanks for the solution too.

 

I didn't know about the VB true is -1

 

Until next time.

 

Rafael

0 Kudos
Message 3 of 3
(4,824 Views)