mercredi 1 juillet 2015

What is an intuitive way to interpret the bitwise operators and masking? Also, what is masking used for?

I'm learning about bitwise operators and masking right now in my computer systems class. However I'm having some trouble internalizing them.

I understand what the operators, &, |, ^, >> (both arithmetic and logical shift), and << DO, but I don't quite get what they're really used for aside from optimizing multiplication and division operations (for >> and <<), and to check if certain bits are on or off (the & operator).

Also, I don't understand what masking is used for. I know that doing x & 0xFF is used to extract the least significant bit in an integer x, but I can't really extrapolate from that to how other kinds of masks (e.g. those that extract the leftmost 1 in a number, that obtain the number of 1s in a number, etc.) are used?

Could anyone please shed some light on this, preferably with some examples? Thank you.

Aucun commentaire:

Enregistrer un commentaire