Simple training demonstration to show the use of union and structure
Fork of OddExample2 by
Diff: main.cpp
- Revision:
- 11:085c63023906
- Parent:
- 10:6c0cd51df4df
--- a/main.cpp Tue Nov 26 14:53:06 2013 +0000 +++ b/main.cpp Tue Nov 26 15:03:49 2013 +0000 @@ -9,8 +9,14 @@ { char Byte; // Use this to map a byte struct { - char Odd: 1; // this is the same as Bit0 - char Others: 7; // Just pad the rest of the bits + char Bit0: 1; // map individual + char Bit1: 1; // bits onto the + char Bit2: 1; // mapped byte. + char Bit3: 1; + char Bit4: 1; + char Bit5: 1; + char Bit6: 1; + char Bit7: 1; }; }; @@ -22,7 +28,7 @@ wait (10); // Wait 10 seconds to connect port - if (cMyNumber.Odd == 1) + if (cMyNumber.Bit0 == 1) serial.printf("%i is odd\n\r", cMyNumber.Byte); else serial.printf("%i is even\n\r", cMyNumber.Byte);