??? 02/26/09 09:20 Read: times |
#162873 - Use #define names Responding to: ???'s previous message |
Fernando Calix De Lima said:
HI,
How can I assign a value in binary to a variable using the C ANSI ? as in assembler > mov a,#00001001B ; 9 in bin Calix Either #define all binary values as Per suggested, Or write the expression as bit positions: variable = (1<<3) | (1<<0); // 9 in decimal You normally want to use binary constants for things like setting a particular bit in a special function register. So you may: #define LED_RED 3 #define LED_GREEN 0 #define LED_BLUE 1 variable = (1<<LED_RED) | (1<<LED_GREEN) | (1<<LED_BLUE); // RGB lit variable = (1<<LED_RED) | (0<<LED_GREEN) | (1<<LED_BLUE); // R_B lit David. |
Topic | Author | Date |
Bin in C | 01/01/70 00:00 | |
Possible solution | 01/01/70 00:00 | |
You need to check if this works with your compiler | 01/01/70 00:00 | |
Does it work with any? | 01/01/70 00:00 | |
popular demand | 01/01/70 00:00 | |
My compiler is IAR | 01/01/70 00:00 | |
because that's a non-standard (non-ANSI) extension | 01/01/70 00:00 | |
What made you beleive that it would work? | 01/01/70 00:00 | |
Use #define names | 01/01/70 00:00 | |
Yes, but... | 01/01/70 00:00 | |
Use macros for that. | 01/01/70 00:00 | |
facilitates my understanding | 01/01/70 00:00 | |
Working with flags | 01/01/70 00:00 | |
how I do it | 01/01/70 00:00 | |
I use a macro![]() | 01/01/70 00:00 |