• 0

[C/C++] Rotate a 0...?


Question

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

  • 0
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

  • 0

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.