Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
This is a simple 4 bit up counter.
Author: Christian Lerche Date: 05-12-2009 MCU: LPC1768 Notes: Simple graycode upcounter, using onboard LEDs. */ #include "mbed.h" BusOut LEDs(LED4, LED3, LED2, LED1); // Make 4 bit bus with LEDs unsigned char i; // Char to read for LEDs int main() { // Main structure i=0; // initialize i to 0 while(1) { // While-loop (Do forever) LEDs=i^(i>>1); // This converts the binary to graycode wait(2); // Wait for .5 seconds i=i+1; // Every loop, add one to i if(i==16) { // If i is 16, make i 0 i=0; // This makes it 0 } // End of if } // End of while-loop (Do not anymore) } // End of main structurePlease can someone explain what the following statements actually do:
What does the '^' hat mean?
As I understand it 'i>>1' converts the binary to graycode But I have also seen 'i>>2' and 'i>>3'
Does this also convert it to graycode?
Cheers David