Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/26/09 10:43
Read: times


 
Msg Score: +1
 +1 Informative
#162880 - Use macros for that.
Responding to: ???'s previous message
There are nice macros for 8,16,32 bit binary values.

See for example:

http://www.embeddedrelated.com/usenet/em...9067-1.php

/**
* Binary constant generator macros evaluating to compile-time constants
* Sample usage:
* unsigned char x = BIN(01010101);
*/

/* Helper macros HEX__ and B8__ not to be used directly
*/
#define HEX__(n) 0x##n##UL
#define B8__(x) (
(((x)&0xF0000000UL)?0x80:0) |
(((x)&0x0F000000UL)?0x40:0) |
(((x)&0x00F00000UL)?0x20:0) |
(((x)&0x000F0000UL)?0x10:0) |
(((x)&0x0000F000UL)?0x08:0) |
(((x)&0x00000F00UL)?0x04:0) |
(((x)&0x000000F0UL)?0x02:0) |
(((x)&0x0000000FUL)?0x01:0))

/* For up to 8-bit binary constants
*/
#define BIN(b) ((unsigned char)B8__(HEX__(b)))

Best reagrds
J. Christoph

List of 15 messages in thread
TopicAuthorDate
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      

Back to Subject List