void main(void) { printf("Hello 9S12"); } |
void main(void) { unsigned char u8bit; // Unsigned 8-bit number signed char s8bit; // Signed 8-bit number unsigned short u16bit; u8bit = 166; printf("u8bit as an unsigned number = %u\n",u8bit); printf("u8bit in decimal = %d\n",u8bit); printf("u8bit in hex = %x\n",u8bit); s8bit = u8bit; printf("s8bit as a signed number is = %d\n",s8bit); u16bit = 0xABCD; // Hex numbers have the 0x prefix printf("u16bit is = %d\n",u16bit); } |
void main(void) { unsigned char sw1, sw2, lt; //declare two switches and 1 light sw1 = 0x01; sw2 = 0x00; // light ON only of both sw1 and sw2 are ON if (sw1 & sw2) { // Condition check lt = 0x01; printf("Light On"); } else { lt = 0x00; printf("Light Off"); } } |
void main(void) { unsigned char anum, bnum; anum = 0x2F; bnum = 0xF9; //Mask out (clear) all the other bits of anum except the 5th bit anum = anum & 0x10; anum = anum>>3; // right shift it by three places //Mask out (clear) all the other bits of bnum except the 2nd bit bnum = bnum & 0x02; if (anum == bnum) { printf("yes"); } else { printf("no"); } } |
void main(void) { //Declare below a 8-bit unsigned number called foo // Declare any additional variables if needed //Initialize foo to the hexadecimal value AB //Write code (possibly more than 1 line) to swap the // lower and upper 4-bits of foo; After executing your // statements foo should have the value BA in hex. // The following if-then-else statement // prints the success or failure of your swap code written above if (foo == 0xBA) { printf(“Output of Homework 2: Swap Successful”); else { printf(“Output of Homework 2: Swap Failed"); } } |
Output of Homework 2: Swap Successful |