XanoZuke Posted July 13, 2009 Share Posted July 13, 2009 Hello everyone! I have a problem, I'm programming an Arduino Board and I need to output the following sequence: 11111110 11111101 11111011 11110111 11101111 And so on, so I was searching over the internet if there's a way to rotate a 0 instead of a 1, can anyone help me here? Link to comment Share on other sites More sharing options...
0 Mike Posted July 13, 2009 Share Posted July 13, 2009 x = ~x; x = x << 1; x = ~x; Should do it. May be a shorter way of doing it though. Link to comment Share on other sites More sharing options...
0 XanoZuke Posted July 14, 2009 Author Share Posted July 14, 2009 x = ~x; x = x << 1; x = ~x; Should do it. May be a shorter way of doing it though. Nice, thanks :D But if "~" negates the variable then what does "!" does? Link to comment Share on other sites More sharing options...
0 Clinteger Posted July 14, 2009 Share Posted July 14, 2009 The logical "not" is not the same as the bitwise "not." ! (logical not) treats the whole value as one boolean, changing between true and false; ~ (bitwise not) performs logical not on each bit, turning 0 to 1 and a value of something other than 0 to 0. Link to comment Share on other sites More sharing options...
0 XanoZuke Posted July 14, 2009 Author Share Posted July 14, 2009 The logical "not" is not the same as the bitwise "not."! (logical not) treats the whole value as one boolean, changing between true and false; ~ (bitwise not) performs logical not on each bit, turning 0 to 1 and a value of something other than 0 to 0. Dude I own you money :p Thank you very much :D Link to comment Share on other sites More sharing options...
Question
XanoZuke
Hello everyone!
I have a problem, I'm programming an Arduino Board and I need to output the following sequence:
11111110
11111101
11111011
11110111
11101111
And so on, so I was searching over the internet if there's a way to rotate a 0 instead of a 1, can anyone help me here?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts