NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Everything Else » Operators

June 11, 2011
by JoyceChee
JoyceChee's Avatar

What does this "|=" operator in C programming means?

Also, what does "(1<<ADEN)" means in C programming?

Hope someone would help. Thanks.

June 11, 2011
by dgikuljot
dgikuljot's Avatar

The line next to the equal sign is the bitwise or operator. Just a quick question, how do you actually type the bitwise or operator on the keyboard.

June 11, 2011
by dgikuljot
dgikuljot's Avatar

NVM i found the key,but JoyceChee that symbol is the or operator, in the nerdkits guide where it explains bits, bytes and stuff it explain how to use or and and operators

June 12, 2011
by JoyceChee
JoyceChee's Avatar

Thanks dgikuljot. does |= means "or equal"? what is the function of this operator then?

June 13, 2011
by bretm
bretm's Avatar
x |= y;

is the same as

x = x | y;

just as

x += y;

is the same as

x = x + y;

ADEN means nothing in C. It's a macro, which means it's converted into C by the pre-processor. In the case of all the bit-shift macros it just boils down to a constant integer value, e.g. 3. So (1<<ADEN) means (1<<3) which means 8 (assuming ADEN is 3, I'm just making that part up, I don't know what its value is).

June 13, 2011
by Ralphxyz
Ralphxyz's Avatar

Huh? Isn't ADEN the 7th bit of the ADCSRA Register.

Doesn't (1<<ADEN) mean 1 left shifted 7 places? Which essentially turns the ADC on.

23.9.2 ADCSRA – ADC Control and Status Register A

Bit 7 – ADEN: ADC Enable
Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the ADC off while a 
conversion is in progress, will terminate this conversion.

So

ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);

Would turn on the bit 7, bit 2, bit 1 and  bit 0      
ADCSRA = 10000111

At least that is what I have been led to believe would happen by those that know so much more than I.

Ralph

June 13, 2011
by mongo
mongo's Avatar

and I thought << was just a pointy hat, <<;)'

June 14, 2011
by Rick_S
Rick_S's Avatar

LOL LOL

June 14, 2011
by bretm
bretm's Avatar

I'm sure you're right about ADEN being 7. I didn't have a reference in front of me so I made up the number 3, which I tried to point out by saying "assuming ADEN is 3, I'm just making that part up, I don't know what its value is".

June 14, 2011
by Ralphxyz
Ralphxyz's Avatar

Thanks bretm, I hope JoyceChee got a usable answer, no thanks to the Funny Fellows.

Usually your answers are so explicit it kinda threw me with your generalized answer, which you did qualify.

Following your general C programming logic ADEN could have been a variable or any other value holding aspect of the C language.

I "assumed" JoyceChee was referencing AVR programing when they asked about [quote] Also, what does "(1<<ADEN)" means in C programming? [/quote] even though they asked "in C programming".

I am just amazed that I was able to offer an answer.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that you can read diagnostic data from some cars with a NerdKit? Learn more...