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.

Microcontroller Programming » what the heck does << mean?

January 29, 2010
by Ralphxyz
Ralphxyz's Avatar

Sorry I am new to C programming and didn't get far in High Scholl math (algebra 1 D) so some symbols (notations) throw me.

  1. result = result + (temp<<8);
  2. 11011010 & ~(1<<3) =

What exactly does this say?

Is the << in 1. the same as the << in 2.?

Thanks for your tolerante help, Ralph

January 29, 2010
by treymd
treymd's Avatar

it is bitwise arithmetic. basically in that operation you are shifting bits 3 to the left.

0000 0001

becomes

0000 1000

January 29, 2010
by treymd
treymd's Avatar

There are a few other operators that work on the bit level in C, working on bits is important when dealing with microcontrollers because you are literally controlling pins with a single bit and you need to play some games to isolate and operate on the one(s) you need while leaving the others alone. Getting good with bitwise operations will give you tremendous power over what the MCU does.

here is a decent reference (a little wordy, but it has it all)

http://www.cprogramming.com/tutorial/bitwise_operators.html

January 29, 2010
by Ralphxyz
Ralphxyz's Avatar

Thanks for the rapid replies.

The << is the left shift operator a >> would be a right shift operator.

Way way back in the depths of my mind I knew that buts thanks alot for the help.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that you can control multiple LEDs from one microcontroller output? Learn more...