Note how the outcome follows the mask in this case.Īlthough the values differ every time, you know that when you got something nonzero, the bit you are testing must be high!Īnd if all the bits are off you will see this: 0000000000 = 00000000 etc.).Įxample, so let's say all the bits are on, then the logical AND output will look like this: 0000001111 = 00000001 Remember: the outcome of this AND operation is still multiple bits - not a single bit, so we can't look for a value of 1 (we'd also have to test for the cases 2, 4, 8. If you want to go in reverse, you initialize mask with (1 >= 1).Įvery mask value is bitwise AND-ed ( & operator) with the input value signal to "filter" out that one particular bit we're interested in. Don't know what is needed here, but just so you know. Note: you can also go into the reverse direction, for instance if the receiver wants to see the highest bit first and the lowest last. So in the for loop, this is what the value of mask looks like over time: 00000001 Let's look at some practical values while the program is running (assuming 8 bits). So after the test of a single bit you will see either zero or a power of 2 value. Remember that the value of a binary word with only one bit set always corresponds to a power 2 value by definition. In combination with the logical AND-function, you can see it as a filter that gives you only the value that particular bit corresponds to or nothing (zero). This mask is used to test each bit in "isolation". The goal is to only have one bit set in the mask at all times. Here mask is the variable that will always contain a "power of 2" value.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |