I'm working with one of Herb Schildt's programs that uses a mask to print an integer's binary equivalent. I've never used a mask before and I think I understand how it's working, but I want to make sure. Let's say I want to print the binary equivalent of the integer 123(0111 1011). Let's say my mask is defined as 1000 0000(which I guess would be 128).
Now the first time through I AND the bits in the leftmost column:
That will print a 0. Then my right shift operator which is defined in my loop header(mask >>>= 1)will shift the 1 in my mask over to the right by one column, so now my mask looks like 0100 0000. Then the process repeats and now I AND the bits in the second column from the left:
That will print a 1. Then my right shift operator shifts the 1 in my mask over to the right by one place and the whole business repeats.
My question is how does the compiler know only to work with one column at a time? The compiler only works with the column that has the 1 bit in my mask. Is this why it's called a mask? Because all the other columns in my mask have zero's in them, it basically makes the compiler blind to all those other columns, so in effect the compiler only see's the particular column that is currently holding the 1 bit in my mask?