![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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. Last edited by Pommie; 6th June 2007 at 01:32 AM. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
Thanks! That worked beautifully!
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| naming a pin or bit question | hotrodhed120 | Micro Controllers | 7 | 8th May 2007 04:50 PM |
| Sync Problem | Marc_Urito | Micro Controllers | 3 | 29th April 2007 03:21 PM |
| Counter 555+ 4 bit binary counter | psymon | Electronic Projects Design/Ideas/Reviews | 12 | 25th April 2007 08:51 AM |
| Query in 32 bit Parallel CRC...urgent | pra.vlsi | Electronic Projects Design/Ideas/Reviews | 1 | 17th April 2007 12:46 PM |
| Need some help with a code provided by ATMEL | ikalogic | Micro Controllers | 1 | 23rd January 2007 02:45 PM |