Hi, How to represent a binary number in C51? I wrote, for example, 11110000b but the C51 don't agree! Please, answer me. Thank you. Hoang Kong Kong. Ha Noi-Viet Nam.
The 'C' language does not have a notation for binary numbers. Surprising, disappointing - but true! :-( That's just 'C' for you. http://www.keil.com/forum/docs/thread1064.asp
Thank you very much! Now I understand it. (I'm a beginner for 8051 and C51). Hoang Kong Kong.
may be u can translate the .c into .asm first and than u can make a change on it. :) Best Regards, Andy Mario
"I'm a beginner for 8051 and C51" Note that this has nothing specifically to do with the 8051 or C51 - it is plain, standard, 'C'
Well, may I suggest a little hint? (= You see, some C compilers have binary notation (like, 0B, 0Bx etc). But pure ANSI C does not. Anyway, if you set and read about that language so have found one magic word called "MACRO". Okay, it's not easy to create such macro on-the-fly if you are not familar with C and binary/octal/decimal formats but... Here you have got it: #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)))) Well, it's hard to imagine what does it do (= But just put these lines above your code and use something like: unsigned char b1, b2; b1 = bin(10101010); // 0xAA b2 = bin(01010101); // 0x55 Note: I do not know, does it work in Keil C or not; at least, in pure ANSI C it does work correctly. Good days!