Solved

# Use of Operator &= in C

Posted on 2003-02-23
Medium Priority
194 Views
Hi,
Can anyone please let me know the use/meaning of operator &=

eg from a book:

#define L_FIX
#define X_BIAS 0x0010
#define REG_2 2
#define l_tone_on 1

{
#ifdef L_FIX
if ((addr == REG_2) && (l_tone_on)) {
return;
}
}
#endif
}

Thanks
0
Question by:cbeginner
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 8

Accepted Solution

akshayxx earned 100 total points
ID: 8006011
if u have any done electronics courses .. then u might have idea of what's the meaning of AND

like 1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
1 AND 1 = 0

this '&' operator in C also same thing .. the difference being it works on the binary representation of the number

2 in binary will be '10'
3 will be   '11'

so 2 & 3 will be 11 & 10 = 10 = 2

and in above case when u do
a&=b; this means
a= a&b;
operate & operator on 'a' and 'b' and assign it to 'a'

& and | operators are used to set the particular bit  ( specified in the MASK ) to 1 OR 0.. and also to know whats the bit value

i hope u can now understand how it is being used in above particular case..
0

LVL 8

Expert Comment

ID: 8006022
>>the difference being it works on the binary representation of the number
actually no difference :P
0

Author Comment

ID: 8006122
Thanks for excellent explanation
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
###### Suggested Courses
Course of the Month12 days, 6 hours left to enroll