Writing to partially reserved registers of sensors
You always write a whole byte when you set the register. You only need to &quot;mask out&quot; those bits if there's a danger that you may inadvertently set them to 1, for instance through some value over flow from other bits when combining values together to form that byte.
If you're not doing that then there's nothing to mask out.  For instance if you just want to set a specific set of bits then just set that value - 0b00101001 is going to be 0b00101001 whether you mask it or not.
If you decide you really want to mask a value, for instance if you are writing a library and you have no control over what an end user may decide to pass to a function, then &amp; (or &amp;=) is your friend:
uint8_t val = 0x55; // 0b01010101 in binary
val &amp;= 0b00111111; // or 0x3F if you want to use HEX
// val is now 0x15 since bit 6 has been &quot;masked&quot; to 0.