Hello, I am working on a binary communication between arduino.
and I have faced some problem, I can't retrieve the correct data by using left shift function.
The following code is what I do for sending and receiving binary data, to make troubleshoot easy, i made it in one program.
First, I break the data to 4 byte from first arduino
Second, I will collect back the data using second arduino and combine the 4bytes back into one value.
I am totally have no idea why is it not giving me back my value, please let me know if you can solve it, thanks!
long val = 12980992;
/*to send out from first arduino*/
buffer = val&0xff;
buffer = (val >> 8)&0xff;
buffer = (val >> 16)&0xff;
buffer = (val >> 24)&0xff;
int start = 0;
/*to retrieve by second arduino*/
num = buffer[start];
num = (buffer[start + 1] <<8) | num;
num = (buffer[start + 2] <<16) | num;
num = (buffer[start + 3] <<24) | num;