mardi 6 décembre 2016

Bitwise operation inside if condition c++

I wrote this code:

            for(int i = 0; i <= 0xF; ++i){
                if((m & (1 << i)) != 0){
                    count[v][i] = true;
                }else{
                    printf("Error\n");
                }
            }

where m can be: 1, 2, 4, .., 16. But my code doesn't enter in then branch, for example with m equals 4 and i equals 2 I obtain "Error". Why?

Aucun commentaire:

Enregistrer un commentaire