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.

Doubt regarding Operators

Status
Not open for further replies.
The & operator works with bits and the && operator works with states like boolean.

x = 0x05 & 0xff; /* working with bits */

if(switch_on && fuse_alight){ /* working with boolean */
run_like_f;
}
 

& helps you did bitwise operation, i.e. is actually performing the boolean arithmetic with individual 0's & 1's of two unsigned quantities. The result of it's operation is thus a numeric quantity (treated as unsigned, but C as a language allows you to break that).
&& is a logical operator, which operates on quantities that have logical-meaning of true/false, and the result of it's operation is also either true/false (not a numeric quantity)
 

In an application standpoint.

& is used for performing bitwise operation, such as if you want something like:
result = 0xFF & 0x00; //result = 0

but && operator is used for doing comparison such as:

if( (result > 0x01) && (result < 0x04)) ...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top