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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/06/06 07:42
Modified:
  09/06/06 07:43

Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#123729 - C style
Responding to: ???'s previous message
Erik Malund said:
if (var & 0x80)
{
  var <<= 1;
  var != 0x01;
}
else
{
  var <<= 1;
}

Oh, this is not C-stylish enough. If I'd C, I'd certainly write something like:
var = (var << 1) | ((var & 0x80) ? 1 : 0);

Jan Waclawek

PS. Of course, you don't need the rotation for the bitshift (I2C) routine, you need shift which IS inherent in C (albeit not in '51, fortunately).



List of 19 messages in thread
TopicAuthorDate
RL & RLC inst in C            01/01/70 00:00      
   yes, they are            01/01/70 00:00      
      yes, they are            01/01/70 00:00      
         mistype            01/01/70 00:00      
      Choose the best tool for the job.            01/01/70 00:00      
      another option (without if)            01/01/70 00:00      
      C style            01/01/70 00:00      
         May Be This Way            01/01/70 00:00      
            No, that won't work!            01/01/70 00:00      
               ways to skin the cat            01/01/70 00:00      
                  Compiler dependant            01/01/70 00:00      
                     compiler independent, but still very ugly version            01/01/70 00:00      
               Thank You            01/01/70 00:00      
         A very important point!            01/01/70 00:00      
      It is nice C            01/01/70 00:00      
         Not necessarily            01/01/70 00:00      
   Problem solved            01/01/70 00:00      
   Keil-specific            01/01/70 00:00      
      Thank you            01/01/70 00:00      

Back to Subject List