?
Solved

Use of Operator &= in C

Posted on 2003-02-23
3
Medium Priority
?
194 Views
Last Modified: 2010-04-15
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
#define addr 2

void hw_write (byte addr, word mask, word data)
{
  #ifdef L_FIX
   if ((addr == REG_2) && (l_tone_on)) {
   mask &= ~X_BIAS;
   if (mask == 0) {
  return;
  }
 }
#endif
}

Thanks
0
Comment
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
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
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

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

Author Comment

by:cbeginner
ID: 8006122
Thanks for excellent explanation
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question