I am trying to understand how to use Bitwise AND to extract the values of individual bytes.
What I have is a 4-byte array and am casting the last 2 bytes into a single 2 byte value. Then I am trying to extract the original single byte values from that 2 byte value. See the attachment for a screen shot of my code and values.
The problem I am having is I am not able to get the value of the last byte in the 2 byte value.
How would I go about doing this with Bitwise AND?

Your 2byte integer is formed with the values 3 and 4 (since your pointer is to
a[1]). As you have already seen in your tests, you can get the3by applying the mask0xFF. Now, to get the4you need to remove the lower bits and shift the value. In your example, by using the mask0xFF00you effectively remove the3from the 16bit number, but you leave the4in the high byte of your 2byte number, which is the value1024 == 2^10— 11th bit set, which is the third bit in the second byte (counting from the least representative)You can shift that result 8 bits to the right to get your
4, or else you can ignore the mask altogether, since by just shifting to the right the lowest bits will disappear:More interesting results to test bitwise and can be obtained by working with a single number: