From: Jesus Calvino-F. <Je...@ec...> - 2002-07-30 21:08:59
|
Hi, As far as I know binary constants are not supported in C. Many years ago when I switched from PLM to C that was the only think I really missed... Anyhow, the work around I use for 8 bit numbers is to define each one of them in an include file. The file can be created with a simple program like: --- cut here --- #include <stdio.h> void main (void) { char binnum[9]="00000000"; int i, j, mask; for(j=0; j<256; j++) { for(i=0, mask=0x80; i<8; i++) { binnum[i]=(mask&j)?'1':'0'; mask/=2; } printf("#define B%s (0x%02x)\n", binnum, j); } } --- cut here --- Suppose the previous file creates an executable called 'binconst.exe'. The include file can be created by executing: binconst > binnums.h 'binnums.h' should look like: #define B00000000 (0x00) #define B00000001 (0x01) #define B00000010 (0x02) . . . #define B11111110 (0xfe) #define B11111111 (0xff) Just #include "binnums.h" into your program and use the binary constants you need... At 01:03 PM 7/30/02 -0700, Erik Walthinsen wrote: >After spending the last week learning PIC programming from scratch with >asm while working up to a complete development environment that doesn't >suck (webpage with docs, code, tips & tricks coming soon), I've gotten >somewhat used to having binary constants, i.e. b'01001110'. A search >through the entire sdcc source tree doesn't reveal any obvious way to use >such constants in C. Am I missing something, or is that indeed a feature >that hasn't been implemented? If so, what would it take to add them? > >TIA, > Omega > > Erik Walthinsen <om...@te...> - System Administrator > __ > / \ GStreamer - The only way to stream! > | | M E G A ***** http://gstreamer.net/ ***** > _\ /_ > > > >------------------------------------------------------- >This sf.net email is sponsored by: Dice - The leading online job board >for high-tech professionals. Search and apply for tech jobs today! >http://seeker.dice.com/seeker.epl?rel_code=31 >_______________________________________________ >Sdcc-user mailing list >Sdc...@li... >https://lists.sourceforge.net/lists/listinfo/sdcc-user |