# What's the purpose of ANDing a bit mask with all bits set to a value?

I'm adapting an algorithm for calculating a CRC 16-bit CCITT (XModem) value from an ASCII input. I've found some code here. I'm using the function the poster has in his question, but I've noticed at the bottom he does this:

calcrc = crc And &HFFFF


What's the purpose of applying such a bit mask that is all 1s to a value? Doesn't that just return the value again?

• It could be because the code is mechanically generated from a template. It could be there also because some situation require changing it, and having it in place make it easy to make sure the masking is done at the right place. I have done that on occasion. Feb 25 '15 at 18:00

The reason is crc that it's calculating is defined to be a 16-bit value, the And &HFFFF will truncate the most significant bit outside the 16-bit range if there is any overflow during the calculation.