binary.h
Go to the documentation of this file.
00001 /* Binary constant generator macro
00002 By Tom Torfs - donated to the public domain
00003 */
00004 
00005 /* All macro's evaluate to compile-time constants */
00006 
00007 /* *** helper macros ***/
00008 
00009 /* turn a numeric literal into a hex constant
00010 (avoids problems with leading zeroes)
00011 8-bit constants max value 0x11111111, always fits in unsigned long
00012 */
00013 #define HEX__(n) 0x##n##LU
00014 
00015 /* 8-bit conversion function */
00016 #define B8__(x) ((x&0x0000000FLU)?1:0) \
00017 +((x&0x000000F0LU)?2:0) \
00018 +((x&0x00000F00LU)?4:0) \
00019 +((x&0x0000F000LU)?8:0) \
00020 +((x&0x000F0000LU)?16:0) \
00021 +((x&0x00F00000LU)?32:0) \
00022 +((x&0x0F000000LU)?64:0) \
00023 +((x&0xF0000000LU)?128:0)
00024 
00025 /* *** user macros ***/
00026 
00027 /* for upto 8-bit binary constants */
00028 #define B8(d) ((int8)B8__(HEX__(d)))
00029 
00030 /* for upto 16-bit binary constants, MSB first */
00031 #define B16(dmsb,dlsb) (((int16)B8(dmsb)<< \
00032 + B8(dlsb))
00033 
00034 /* for upto 32-bit binary constants, MSB first */
00035 #define B32(dmsb,db2,db3,dlsb) (((int32)B8(dmsb)<<24) \
00036 + ((int32)B8(db2)<<16) \
00037 + ((int32)B8(db3)<< \
00038 + B8(dlsb))
00039 
00040 /* Sample usage:
00041 B8(01010101) = 85
00042 B16(10101010,01010101) = 43605
00043 B32(10000000,11111111,10101010,01010101) = 2164238933
00044 */


sr_external_dependencies
Author(s): Ugo Cupcic
autogenerated on Mon Jul 1 2019 20:06:25