<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to represent a binary number in C51?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/15943/how-to-represent-a-binary-number-in-c51</link><description> Hi, 
How to represent a binary number in C51? I wrote, for example, 11110000b but the C51 don&amp;#39;t agree! 
Please, answer me. Thank you. 
Hoang Kong Kong. 
Ha Noi-Viet Nam. </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/95565?ContentTypeID=1</link><pubDate>Mon, 07 Jul 2003 03:18:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d70710f8-efc6-458f-954f-ef99807f42bd</guid><dc:creator>Oleg Sergeev</dc:creator><description>&lt;p&gt;Well, may I suggest a little hint? (=&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;MACRO&amp;quot;. Okay, it&amp;#39;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:&lt;br /&gt;
&lt;br /&gt;
#define bin(a) ((( (a/10000000*128) + \&lt;br /&gt;
                        (((a/1000000)&amp;amp;1)*64) + \&lt;br /&gt;
                        (((a/100000)&amp;amp;1)*32) + \&lt;br /&gt;
                        (((a/10000)&amp;amp;1)*16) + \&lt;br /&gt;
                        (((a/1000)&amp;amp;1)*8) + \&lt;br /&gt;
                        (((a/100)&amp;amp;1)*4) + \&lt;br /&gt;
                        (((a/10)&amp;amp;1)*2) + \&lt;br /&gt;
                        (a&amp;amp;1)) * (a/10000000)) + \&lt;br /&gt;
                     (( ((a/262144)*64) + \&lt;br /&gt;
                        (((a/32768)&amp;amp;1)*32) + \&lt;br /&gt;
                        (((a/4096)&amp;amp;1)*16) + \&lt;br /&gt;
                        (((a/512)&amp;amp;1)*8) + \&lt;br /&gt;
                        (((a/64)&amp;amp;1)*4) + \&lt;br /&gt;
                        (((a/8)&amp;amp;1)*2) + \&lt;br /&gt;
                        (a&amp;amp;1)) * (1-(a/10000000))))&lt;br /&gt;
&lt;br /&gt;
Well, it&amp;#39;s hard to imagine what does it do (=&lt;br /&gt;
But just put these lines above your code and use something like:&lt;br /&gt;
&lt;br /&gt;
unsigned char b1, b2;&lt;br /&gt;
&lt;br /&gt;
b1 = bin(10101010);  // 0xAA&lt;br /&gt;
b2 = bin(01010101);  // 0x55&lt;br /&gt;
&lt;br /&gt;
Note: I do not know, does it work in Keil C or not; at least, in pure ANSI C it does work correctly.&lt;br /&gt;
&lt;br /&gt;
Good days!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/95561?ContentTypeID=1</link><pubDate>Sat, 05 Jul 2003 16:53:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5c3dcf31-b468-4b1a-a0f5-0000e4aaf035</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;I&amp;#39;m a beginner for 8051 and C51&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Note that this has nothing &lt;i&gt;specifically&lt;/i&gt; to do with the 8051 or C51 - it is plain, standard, &amp;#39;C&amp;#39;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/95572?ContentTypeID=1</link><pubDate>Sat, 05 Jul 2003 10:38:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6e52e060-7cfd-4b68-a8d4-9ae29bef317d</guid><dc:creator>Andy Mario</dc:creator><description>&lt;p&gt;may be u can translate the .c into .asm first&lt;br /&gt;
and than u can make a change on it. :)&lt;br /&gt;
&lt;br /&gt;
Best Regards,&lt;br /&gt;
Andy Mario&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/71554?ContentTypeID=1</link><pubDate>Sat, 14 Jun 2003 11:32:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:76f62475-a87d-4cb7-b84e-9608b803ba43</guid><dc:creator>Hoang Kong Kong</dc:creator><description>&lt;p&gt;Thank you very much! Now I understand it.&lt;br /&gt;
(I&amp;#39;m a beginner for 8051 and C51).&lt;br /&gt;
Hoang Kong Kong.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/40390?ContentTypeID=1</link><pubDate>Thu, 12 Jun 2003 03:34:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c9759e11-f118-41b1-85e2-bb661145032e</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;The &amp;#39;C&amp;#39; language does &lt;i&gt;&lt;b&gt;not&lt;/b&gt;&lt;/i&gt; have a notation for binary numbers.&lt;br /&gt;
Surprising, disappointing - but true!  :-(&lt;br /&gt;
&lt;br /&gt;
That&amp;#39;s just &amp;#39;C&amp;#39; for you.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/forum/docs/thread1064.asp"&gt;http://www.keil.com/forum/docs/thread1064.asp&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to represent a binary number in C51?</title><link>https://community.arm.com/thread/40393?ContentTypeID=1</link><pubDate>Thu, 12 Jun 2003 03:30:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c90c3030-a214-4100-b0fc-59b0478d06fd</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;In standard &amp;#39;C&amp;#39; you can&amp;#39;t do this. You have a choice of hex, octal or decimal.&lt;br /&gt;
&lt;br /&gt;
I&amp;#39;m not aware of Keil having a language extension to do this.&lt;br /&gt;
&lt;br /&gt;
Stefan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>