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 » HAVING A NOT PROBLEM

November 18, 2010
by FERGALICOUS
FERGALICOUS's Avatar

i understand AND. i understand OR. what i don't get is NOT. if NOT receives 2 x bits and they're both 00 = then it would return a 1 ? if it received 2 x bits and they're both 1 = then it would return a 0 ? so what happens if it receives a 1 and a 0 or a 0 and a 1, what does it return ?

November 18, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Fergalicous,

In C (and in any other language where you can deal with bits) there is a distinction between logical operators and bitwise operators. The logical operators && (and), || (or), and ! (not) operate on the entire expression as a whole. The && operator will return a logical true value if both operands are a logical true for example. So the ! operator which is the logical not operator will operate on the entire expression. So in your examples the ! of 0b01, or 0b10 will both return 0 (a logical False) since the inputs are both non-zero (a logical True).

C also has bitwise operators, which operate on the operands bit by bit. These are the & (and), | (or) and ~ (not), as well as others. The ~ in this case will flip every bit in the operand so ~0b00000010 (the 8 bit representation of 2), results in 0b11111101.

Hope that makes sense, let me know if you have any questions.

Humberto

November 18, 2010
by FERGALICOUS
FERGALICOUS's Avatar

uh ? i was just confused before. what does 0b01 mean ?

November 18, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Fergalicous,

I apologize for throwing in a convention and not explaining it. I used the 0b to make it clear that I was talking about a binary representation of the number. To differentiate from decimal representation we often use a prefix when not writing down decimal numbers. Perhaps you have seen hex numbers written with the 0x prefix, life 0xFF. It just helps make things a little more clear so you don't think I meant ten when I was trying to write the binary representation of 2.

Humberto

November 18, 2010
by FERGALICOUS
FERGALICOUS's Avatar

yep ok that helps a lot more. isn't it about 2am in the states ? you should get some sleep tiger.

November 18, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

We are on the west coast. Its only midnight here =).

Humberto

Post a Reply

Please log in to post a reply.

Did you know that 20 LEDs can be controlled from 11 microcontroller pins, to make a twinkling heart outline? Learn more...