Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Bit Select

Status
Not open for further replies.

jbchrist

New Member
Ok....This should be an easy question, but I can't find the answer because I don't know what to look for.

I am writing a program for a PIC16f684, using the PIC C lite complier.

I have a 8 bit value stored and I want to take bit x and store it in a different variable.

How do I do that?

John
 
I would guess,

NewVar = OldVar&(1<<X);

Would issolate the bit. (X = 0 to 7)

Mike.
Edit changed the operator to the bitwise one as PB pointed out.
Note to self, don't post at 2AM after a night out.:eek:
 
Last edited:
Using the && relational operator with an actual C compiler would be a pretty hard bug to find. You should use the bitwise & operator which will get you the intended result.

I would also highly recommend that you examine carefully the compiler's assembly language output to verify that it is doing what you want it to do.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top