NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
caracasnet
Posts: 17
0 Kudos
Accepted Solution

NOT function wrong behaviour

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

 

Member
AndreasK
Posts: 199

Re: NOT function wrong behaviour

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

 

 

Member
caracasnet
Posts: 17
0 Kudos

Re: NOT function wrong behaviour

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

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page