|
From: | Florian Bantner |
Subject: | Re: [avr-gcc-list] efficiency of assigning bits |
Date: | Mon, 14 Mar 2005 17:05:49 +0100 |
User-agent: | Mutt/1.3.28i |
A little Perl-Script can do the job: --- genbin2hex.pl ---------------------- #!/usr/bin/perl sub tobin( $ ){ $n = shift; $res = ""; for( $c = 128; $c > 0; $c = int( $c / 2 ) ){ if( int( $n / $c ) == 1 ){ $n -= $c; $res .= "1"; } else { $res .= "0"; } } $res; } print "#ifndef BIN2HEX_H\n"; print "#define BIN2HEX_H\n\n"; for( $i = 0; $i < 256; $i++ ){ print "#define 0b" . tobin( $i ) . " " . $i . "\n"; } print "\n#endif\n"; ---/genbin2hex.pl ---------------------- Will generate Output: #ifndef BIN2HEX_H #define BIN2HEX_H #define 0b00000000 0 #define 0b00000001 1 ... #define 0b11111111 255 #endif perl genbin2hex.pl > bin2hex.h and #include "bin2hex.h" Wrote it in the beginning of my avr-programming. By now I personally find 0x7f better than 0b01111111. Florian -- -------------------------------------------------------- Florian Bantner fon +49 (0)941 599 854 4 AXON-E interaktive medien fax +49 (0)941 599 854 1 technische Leitung mail address@hidden web http://www.axon-e.de gpg public key http://www.axon-e.de/gpg/f.bantner.key hash 1191 0C87 D9DB 3217 ABBA 5223 6D74 AB19 5C9D FC49 --------------------------------------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |