Apprentice coder

Maybe I didn't look back far enough:
did you initialize mask to 1 so you have a bit to shift across?

mask = 1;
for (whatever){
anding operation;
mask = mask<<1;
}