How to parse from word to byte?

I have a question about how Arduino parse from a variable word to a variable byte.
When I have:

word aux;

and I do:

aux = (byte)aux;

How aux has been parsed to a byte? How the value of aux is modified when is converted to a byte?

The better question would be what do you want it to do? If word and byte are both unsigned and the value is 255 or less than you will have no issue. If it is signed between -128 and 127 then you will have no problem. Otherwise you will lose data with this cast.

If you don’t care about the loss of data I would just be explicit and write:

aux = aux & 0xff;

Why not try it yourself?

word w;
byte b;

void setup() {
  Serial.begin(115200);
  while (!Serial);  // using a Leonardo here
  w = 0x0010;
  b = w;
  Serial.println(b,HEX);
  
  w = 0x1020;
  b = w;
  Serial.println(b,HEX);
}

void loop() {}

The output is:

14:32:39.032 -> 10
14:32:39.032 -> 20

So as said by ToddL1962, the byte only retains the last byte of the word (the least significant byte). A word is an unsigned 2 bytes variable.

Thanks for answering. I've this question because I found a code with this procedure:

void read(word aux)
{
    write((byte)(aux>>8)&0x7f);
    write((byte)aux);
}

The "write" procedure is used to send bits using SPI.
I think that first called to "write" procedure in the "read" method is used to send the most significant byte of the word, and the second to send the last byte of the word.

Also, I don't understand what use has the AND operation in my code, and what use has the AND operation that ToddL1962 propose.
And what is the difference between use 0x7f or 0xff in the AND operation?

ElRodrik:
The "write" procedure is used to send bits using SPI.
I think that first called to "write" procedure in the "read" method is used to send the most significant byte of the word, and the second to send the last byte of the word.

Also, I don't understand what use has the AND operation in my code, and what use has the AND operation that ToddL1962 propose.
And what is the difference between use 0x7f or 0xff in the AND operation?

Your original question did not have the context with it. Now I see why you are asking it.

You are correct in your analysis of the code segment. The 0x7f in the code segment masks out the most significant bit of the most significant byte of aux before writing it to the SPI.