Communication between two Arduinos

Hi, Im working on a project in which I need to communicate an int from Arduino Tx to Arduino Rx. Im using the Software Serial library and I've created an aux Channel called CanalAux. I found a code, which works, but I don't understand it. Could someone help me? Thanks!

unsigned int readFromTx() { unsigned int val; val = Serial.read(); val += ((unsigned int)Serial.read())*256; return val; }

I understand the read function reads a byte, thats why I have to cast it to an int. But why multiply by 256?

//Sends and int by CanalAux

define VAL_SIZE 2

void writeCanalAux(int val) { CanalAux.write((byte*)&val, VAL_SIZE); }

I understand the write receives a byte, thats why i cast the val to a byte. What does the * and the & do?? Thanks a lot!!!

I understand the read function reads a byte,

...but returns an int.

I found a code, which works, but

I'm not going to show you all of it.

(byte*)&val

Take the address of "val" using the & operator (making a pointer to int) and cast the result to be a pointer to byte.

I found a code, which works, but

I'm not going to show you all of it.

I just corrected this because I found it confusing.

@florencia, you need to show the entire code so we can understand the context of the pieces you are having a problem with. And PLEASE use the # icon to display the code correctly.

...R