Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/30/08 20:36
Read: times


 
#158704 - gray to bin
Responding to: ???'s previous message
Here is a n-1 step loop to convert from gray to binary

unsigned char gray_to_bin8(unsigned char n) {
    unsigned char i,rev;
    for (i = 0x80,rev = 0x40; i > 1; i >>= 1, rev >>= 1) {
        if (n & i) {
            n ^= rev;
        }
    }
    return n;
}

Or with one temporary less:
unsigned char gray_to_bin8(unsigned char n) {
    unsigned char i;
    for (i = 0x80; i > 1;) {
        if (n & i) {
            i >>= 1;
            n ^= i;
        } else {
            i >>= 1;
        }
    }
    return n;
}


List of 20 messages in thread
TopicAuthorDate
Gray Code To Binary 8051            01/01/70 00:00      
   huge table            01/01/70 00:00      
      RE: Take a pen and paper            01/01/70 00:00      
   Here are a few places to look...            01/01/70 00:00      
   What for?            01/01/70 00:00      
   Algorithm            01/01/70 00:00      
      Gray Code To Binary 8051            01/01/70 00:00      
         Post it            01/01/70 00:00      
            Yes!            01/01/70 00:00      
               Shifting ?            01/01/70 00:00      
                  Gray Code To Binary 8051            01/01/70 00:00      
                     Posting times            01/01/70 00:00      
   Gray Code To Binary 8051            01/01/70 00:00      
      2^n - 1 is not fast for large n            01/01/70 00:00      
         Ouch            01/01/70 00:00      
            Gray Code To Binary 8051            01/01/70 00:00      
               hardware            01/01/70 00:00      
               gray to bin            01/01/70 00:00      
                  asm            01/01/70 00:00      
                     Gray Code To Binary 8051            01/01/70 00:00      

Back to Subject List