Help with bit-shifting and merging variables

Hi dear friends,

I would like to ask for some of your expertise to help me find the most effective solution for a problem I am facing.

I have a shift register attached to the SPI port of my arduino and what I need to do is send a 16 bit word to another microprocessor.

So the first problem is that I have two independent variables.
One has a with of 10 bits and other has a with of 6 bits. Now, if this was a 16 bit microprocessor I would simply merge them into an int and be done with that. But due to the 8bit nature of the arduino if i decide to merge both into a single word I then have to convert back into two bytes.

in addition to this, I need to run some code to make sure that if the 10bit word overflows, for example 11 bit, I wont have an issue with all the data being wrong. I defenitivelly need the 6 bit variable to always occupy the same bits (10-15)

How would I best deal with this?

God bless you all.

int theWord = 12345;

byte byte1 = theWord & 0xFF; // first the last 8 bits are removed, so the first 8 bits can be stored in a byte

byte byte2 = (theWord >> 8) & 0xFF; // then the remaining 8 bits are shifted to the right and again you remove the last 8 bits, even if nothing should be there, just to be sure.

then you can send both bytes whereever you want them to send and then on the other side you do this

int word = (byte2 <<8) | byte1; // both bytes get merged to the int