Difference between revisions of "Bitfields programming"
From Teknologisk videncenter
m |
m (added Category:C using HotCat) |
||
Line 18: | Line 18: | ||
*[http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc03defbitf.htm IBM on C bitfields] | *[http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc03defbitf.htm IBM on C bitfields] | ||
*[http://tdistler.com/2008/07/21/cc-using-bitfields-effectively Using Bitfields Effectively] (volatile example) | *[http://tdistler.com/2008/07/21/cc-using-bitfields-effectively Using Bitfields Effectively] (volatile example) | ||
+ | |||
+ | [[Category:C]] |
Revision as of 15:40, 25 August 2012
C and C++ programming
Example
#include <stdio.h>
void main( void ) {
struct display {
unsigned format : 1; // 24 hour or 12 hour format
unsigned pm : 1; // PM and AM leds. If 12 hour format pm or am (pm=0 is am)
unsigned alarm : 1; // Alarm on/off LED.
unsigned digit1 : 4; // Hour MSD 7 segment
unsigned digit2 : 4; // Hour LSD 7 segment
unsigned digit3 : 4; // Minute MSD 7 segment
unsigned digit3 : 4; // minute LSD 7 segment
};
Links
- IBM on C bitfields
- Using Bitfields Effectively (volatile example)