Boris Ohayon
2 min readJan 12, 2017

--

Hey, glad to hear it has been useful 🤗

I have updated the article to make it clearer!

As a reminder, we want to extract the the two last hex values from 0xE66B. In order to do this, the mask we are going to apply is 0xFF, which is represented below in binary.

We are going to apply it to the hex 0xE66B, represented below in binary.

Basically, when we apply a mask to another value (AND operator), it selects everything that is 1 in the mask and puts to zero everything else.

A recap of the & operator which is applied bit by bit:
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0

If we come back to our needs, after shifting and the & operation, we finally selected the part we wanted!

--

--