??? 02/27/04 11:54 Read: times |
#65612 - RE: Binary constant macros Responding to: ???'s previous message |
hi,
Peter, macro you posted, is not correct. If produces correct values only if binary number (here: x) starts with '1'. For example: B(11111111) produces 0xFF B(11110000) produces 0xF0 but: B(00001111) produces 0x05 B(01111111) produces 0x1F HINT: due ANSI C rules, any number started with '0' is considered as octal one. Your macro converts it as decimal one that is totally wrong. It is why my macro published on Keil forum, has additional lines to support both cases: #define bin(a) ((( (a/10000000*128) + (((a/1000000)&1)*64) + (((a/100000)&1)*32) + (((a/10000)&1)*16) + (((a/1000)&1)*8) + (((a/100)&1)*4) + (((a/10)&1)*2) + (a&1)) * (a/10000000)) + (( ((a/262144)*64) + (((a/32768)&1)*32) + (((a/4096)&1)*16) + (((a/512)&1)*8) + (((a/64)&1)*4) + (((a/8)&1)*2) + (a&1)) * (1-(a/10000000)))) Regards, Oleg |
Topic | Author | Date |
Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros![]() | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 | |
RE: Binary constant macros | 01/01/70 00:00 |