We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How can a Binary number be used in a program?
Looks like Mr. Torfs has a typo. Further down just above the second of his two(!) signatures in "Sample usage:", he's got the same "... = 85" but this time it's B8(01010101), which is correct.
he's got the same "... = 85" but this time it's B8(01010101), which is correct.
Hmmm. I always thought 01010101 was 0x55. :-)
Jon
"Looks like Mr. Torfs has a typo."
I should have added that the typo is only in his commentary. As far as I know, the macros themselves are fine to use as-is (as-are?).
"I always thought 01010101 was 0x55."
You're closer than I was. Taking 01010101 by itself, I came up with 266305.
if You absolutotally HAVE to do it
#define bin00000001 0x01 ... define bin11111111 0xff
I do some 'binary' definitions this way
in my .h file
sfr S0_TMR2CN = 0xc8; // TIMER 2 CONTROL */ sfr S1_TMR3CN = 0xc8; // TIMER 3 CONTROL sfr S2_TMR4CN = 0xc8; // TIMER 4 CONTROL sbit SB0_TMR2CN_TF = 0xcf; sbit SB1_TMR3CN_TF = 0xcf; sbit SB1_TMR3CN_TR = 0xca; #define SM_TMRxCN_TF 0x80 // oflo/int #define SM_TMRxCN_EXF 0x40 // ext activate #define SM_TMRxCN_EXEN 0x08 // ext stimuli #define SM_TMRxCN_TR 0x04 // run control #define SM_TMRxCN_C_T 0x02 // 1 = counter 0=timer #define SM_TMRxCN_CP_RL 0x01 // 0 = reload, 1 = capture
then in the .c file
//S0_TMR2CN = 0 + SM_TMRxCN_TF + SM_TMRxCN_EXF + SM_TMRxCN_EXEN + SM_TMRxCN_TR + SM_TMRxCN_C_T + SM_TMRxCN_CP_RL; S2_TMR4CN = 0 + SM_TMRxCN_TR + SM_TMRxCN_CP_RL;