Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Bitwise AND with a hex value in MPLAB

Status
Not open for further replies.

ste2006

Advanced Member level 4
Joined
May 1, 2012
Messages
118
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
2,226
Guys i know there will be a simple answer to this but just drawing a blank

I have a simple statement as below but the 0x19 keeps referring to that address as opposed to the actual value

if ((WarningCode & 0x0019) == 1) // Inputs Active
{ }​

Now i have jsut created a variable with 0x19 in it but still wondering what i am doing wrong above??

Thanks,
 

Guys i know there will be a simple answer to this but just drawing a blank

I have a simple statement as below but the 0x19 keeps referring to that address as opposed to the actual value

if ((WarningCode & 0x0019) == 1) // Inputs Active
{ }​

Now i have jsut created a variable with 0x19 in it but still wondering what i am doing wrong above??

Thanks,
I read your post over five times but unfortunately I didn't understand what your problem is. You want to compare what with what?
And what the desired result would be?
 

Sorry,

I want to bitwise compare the value within the variable WarningCode with Hex value 0x19 and if the result is true process the statement below it

Make any sense now??
 

I want to bitwise compare the value within the variable WarningCode with Hex value 0x19 and if the result is true process the statement below it
OK, made sence! :)
You should edit the code as follows:

Code:
if (WarningCode & 0x0019)
{ }


Hope this helped,
Alexandros
 

ok but what was wrong with mine, What if i wanted it !=1 (not equal to one) instead
 

ok but what was wrong with mine, What if i wanted it !=1 (not equal to one) instead
From syntax point of view:
If you write if (a), this is equivalent with if (a != 0).
If you write if (!a), this is equivalent with if (a == 0).

So in our case let us replace 'a' variable with WarningCode&0x0019:
If you write if (WarningCode & 0x0019), this is equivalent with if ( (WarningCode & 0x0019) != 0 ).
If you write if ( !(WarningCode & 0x0019) ), this is equivalent with if ( (WarningCode & 0x0019) == 0 ).

From algebra point of view:
0x19 = 11001b. Let's see this through an example. We will AND 0x19 with 0x09. The result would be 0x09 (1001b).

11001 AND
01001
------------
01001

https://en.wikipedia.org/wiki/Bitwise_operation

So if you use the condition of the original post, then you have a false condition, because the result will not be 1, but 9.
If you use the condition mentioned in post #2, then you have a true condition because 9 is not 0.

Hope it is more clear for you now.
 
Yes perfect, I actually copped it inbetween your posts, Thanks a lot for the help though, This really is a great Forum
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top