Oznog
Active Member
Stupid newbie question- I have a bunch of 8 bit variables in C. Looking at the ADC spec, I need to send the most significant bit first.
I can think of any number of ways to do this, but none are very simple. Is there a really tight way to do this?
With the 8 bit values I think I'm just going to AND it with one of 8 one-hot constants; 10000000, 01000000, etc... and check to see if it's a nonzero result. Is that quickest? Just for kicks, what would you do if it was a 32 bit number?
Ironically, they do begin as constants in this case and it would be far smaller to reverse the bits there, but it just kills the readability of the code. I used to do crap like that, but no longer. Project is too big for stuff like that to be floating around.
I can think of any number of ways to do this, but none are very simple. Is there a really tight way to do this?
With the 8 bit values I think I'm just going to AND it with one of 8 one-hot constants; 10000000, 01000000, etc... and check to see if it's a nonzero result. Is that quickest? Just for kicks, what would you do if it was a 32 bit number?
Ironically, they do begin as constants in this case and it would be far smaller to reverse the bits there, but it just kills the readability of the code. I used to do crap like that, but no longer. Project is too big for stuff like that to be floating around.