# increment by bitwise

Hey! Sorry if this has been discussed. Maybe I don't have the right keywords.

Is it not possible to increment by a bit shifted value? The code below works fine if I change it to onePossibility++; But +=n<<1 does not augment the variable at all.

I want to keep track of three possible movements of four entities, stored neatly in three bytes.

``````for(int n = 0; n<4; n++)
if( var > 1)
{onePossibility+=(n<<1);}
if(var< 1)
{anotherPossibility +=(n<<1);}
if(var == 0)
{aThirdPossibility +=n(<<1);}
``````

Thanks!!

The code below works fine...

That is impossible. Your code cannot possibly make it through the compiler. For many reasons.

I suggest you first get the syntax errors fixed. Adding setup and loop is a great place to start.

You really should provide a sketch complete enough to compile if you want programming help.

Since '<<1' is roughly equivalent to '*2' you could just count by 2's:

``````for(int n = 0; n<8; n+=2)
``````

Note that your 2nd and 3rd 'if' statements are not inside the loop. Perhaps you meant to write:

``````for(int n = 0; n<4; n++) {
if( var > 1)
{onePossibility+=(n<<1);}
if(var< 1)
{anotherPossibility +=(n<<1);}
if(var == 0)
{aThirdPossibility +=n(<<1);}
}
``````