Maker Pro
Maker Pro

logic

MnM

Nov 8, 2011
2
Joined
Nov 8, 2011
Messages
2
This condition is to0 long..and it cause an error in matlab during building it..
can i know what type of solution can be use?like using any logic to represent it,to make it short??

if((RA0|RA1|RA2|RA3)||(RA2&RA3|RA1&RA3|RA1&RA2|RA0&RA2|RA0&RA3))
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The simplification is

if (RA0|RA1|RA2|RA3)

The other clause is superfluous as the first clause is true if any signal is high. Therefore also testing combinations of them is pointless.

Also, the other clause relies on the precedence of operators and you might want to split it up in order to make it clearer to a reader.

And use whitespace, it makes things a lot easier to read.
 

MnM

Nov 8, 2011
2
Joined
Nov 8, 2011
Messages
2
i need to put a condition when press 2 switches,then carry out something.i try this


else
{


if((RA2&RA3)&&!((RA1&RA3)&&(RA1&RA2)&&(RA0&RA2)&&(RA0&RA3)))


and there are still got few others same type condition,when try to run it,it only execute the first condition and the rest it just cant run..is there any way to make it short?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Perhaps you could start with a list of the conditions. Your latest logic says:

if RA2 and RA3 are set and all of the other pairs are not simultaneously set then do something. I doubt that is what you want, and it's mostly superfluous.

I presume you're trying to detect RA2 and RA3 and nothing else, correct?

if (RA2 && RA3 && (!RA0) && (!RA1)) <-- this does that

I'm also concerned with your use of | vs || and & vs &&. What language are you using?
 
Top