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.

Support Forum » trying to understand some basics (Bitwise Operators)

February 27, 2012
by Ragnor
Ragnor's Avatar

I am having some trouble understanding how to perform these operations

11011010 & ~(00001000) = 11010010

11011010 & ~(00001001) = 11010010

11011010 & ~(1<<3) = 11010010

11011010 | (1<<2) = 11011110

Are operations done from left to right or right to left?

I have been staring at this for a couple days and maybe it's just a mental block but I do not see the logical procession in these operations.

If someone could brake it down step by step. I would really appreciate it. I cant wrap my head around when to perform each function in the conversion.

I work out each conversion as many ways as I can think of and do not get the stated result.

I know something is out of step but I am just spinning my gears trying to understand it.

If someone could go over each conversion step by step that would be great. Thnx. I know it's very basic I'm just not getting it.

February 27, 2012
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Rangor,

There is a specified order of operations in C (just like there is normal math). Here is a table that lists the order of precedence for the operators in C. The parts that are relevant here are parenthesis, ~, and logical operators are evaluated in that order. So I'll walk you through the first one:

11011010 & ~(00001000)

First thing that is evaluated is parenthesis. There is just a number in the parenthesis, so that just stays the same

11011010 & ~00001000

Next is the ~ (bitwise not) operator. This just flips all the bits one by one and we get

11011010 & 11110111

Next is the & operator. It does a bitwise AND of each bit in the two operands respectively

11010010

Try the walking through the next couple, and let us know what you get. If you get stuck, let us know where so we can point you in the right direction.

Humberto

Post a Reply

Please log in to post a reply.

Did you know that essentially all power supplies' voltages drop when current is drawn from them? Learn more...