Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ORING in if condition

Status
Not open for further replies.

Arrowspace

Banned
Joined
Jan 23, 2015
Messages
186
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
0
Is this a correct way of using if with ORING

Code:
if((alarm_flag_c1_f1)==((0b01000000)||(0b01100000)||(0b01100010)||(0b00100010) ||(0b01000010)||(0b00100000)||(0b00000010)))
 

It is done like this.


Code C - [expand]
1
2
3
if((alarm_flag_c1_f1 == 0b01000000) || (alarm_flag_c1_f1 == 0b01100000)  || (alarm_flag_c1_f1 == 0b01100010) || (alarm_flag_c1_f1 == 0b00100010) || (alarm_flag_c1_f1 == 0b01000010) || (alarm_flag_c1_f1 == 0b00100000) || (alarm_flag_c1_f1 == 0b00000010)) {
 
}

 
If the 3 bits tested is the only ones used in 'alarm_flag_c1_f1' this should work. If one or more of the rest of the bits are used or not '0', you will have a problem and may not get a true result. To get that you need to AND the variable befor you do the test.

Analyzing your test patterns, you could also just AND with '0b01100010', and skip all the ORing. You are using 3 bits with 7 variants, that leaves only the all '000' variant. As long as atleast one of the 3 bits is '1' your test is true.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top