fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. const int wrap = 255;
  6.  
  7. int x = 1;
  8.  
  9. std::cout << "X = " << x << std::endl;
  10. while( x < 256 )
  11. {
  12. x <<= 1;
  13. std::cout << "X = " << x << std::endl;
  14. }
  15.  
  16. if( x >= 256 ) //the next shift
  17. {
  18. x -= wrap;
  19. std::cout << "X wrapped!" << std::endl << "X = " << x << std::endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
X = 1
X = 2
X = 4
X = 8
X = 16
X = 32
X = 64
X = 128
X = 256
X wrapped!
X = 1