nani92 nani92 - 12 days ago 6
C Question

How to make concatenation between 4 bytes?

I have 4 bytes:

buffer_RX[3]= \x70;
buffer_RX[4]= \xb4;
buffer_RX[5]= \xc5;
buffer_RX[6]= \x5a;


I want to concatenate them in order to have such representation 0x70b4c55a:

I already did this
plaintext[1]= (rx_buffer[3]<<8)|rx_buffer[4];

This is the result that I have:
70b4


plaintext[1]= (rx_buffer[3]<<8)|(rx_buffer[4]<<8)|(rx_buffer[5]<<8)|rx_buffer[6]


It doesn't work.
Please I need help.

Answer

This is one way to do it :

plaintext[1] = (buffer_RX[3] << 24) |
               (buffer_RX[4] << 16) |
               (buffer_RX[5] << 8) | buffer_RX[6];