Simple training demonstration to show the use of bit wise And

Dependencies:   USBDevice mbed

Fork of UnionExample by Jon Fuge

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002 * This program demonstrates determines if a number is odd or even              *
00003 *                                                                              *
00004 * Jon Fuge                                                                     *
00005 * V1.0 26/11/2013 First issue of code                                          *
00006 *******************************************************************************/
00007 
00008 #include "mbed.h"
00009 #include "USBSerial.h"
00010  
00011 USBSerial serial; //Virtual serial port over USB. Use Teraterm as the interface
00012 
00013 int main() {
00014    char cMyNumber = 53; // Set it to an odd number
00015 
00016    wait (10); // Wait 10 seconds to connect port
00017    
00018    if ((cMyNumber & 0x01) == 1)
00019       serial.printf("%i is odd\n\r", cMyNumber);
00020    else
00021       serial.printf("%i is even\n\r", cMyNumber);
00022 
00023    for(;;) {} // Loop forever
00024 }