# receiving a int value on Serial of arduino from a PIC 16F877A

hello all
I have a circuit that counts pieces and then when some ask how much pieces the PIC already count, he deliverer on a serial instruction a value like 15632 for example.I need to work with this value on arduino side which will receive it from the serial port connected to the PIC UART.Since an int variable need 4 bytes on the buffer to received it how can I then rearrange the value to 15632 in a int variable on arduino?

Since an int variable need 4 bytes on the buffer to received it how can I then rearrange the value to 15632 in a int variable on arduino?

Your initial assumption is wrong. An int is two bytes.

The two byte int is sent either most significant byte first or least significant byte first. The first thing to determine is which order is used.

Then, int = msb*256 + lsb.

wow it realy works.
By the way I was convince that an int was 4 bytes.In some languages there are 4 bytes.Why on arduino is 2 bytes? is this because of the CPU on Atmega chip?
Another question if I have a long int( 4 bytes now I presume) can I still use this formula?

If you have control over the PIC software, IMHO it's better to printf() or itoa() the value and then on the arduino side convert from string to int (or long). This avoids msb/lsb and datatype size issues.
Just on opinion...

By the way I was convince that an int was 4 bytes.In some languages there are 4 bytes.Why on arduino is 2 bytes?

The size of an int generally depends on the amount of memory that a computer has. An int, as a pointer, that is two bytes long can address 65,536 memory locations. That is nowhere near enough on a PC, but it is plenty on an Arduino that has 2 to 8 K of memory.

Another question if I have a long int( 4 bytes now I presume) can I still use this formula?

Yes, One byte gets shifted 24 places. The next byte gets shifted 8 places. The 3rd byte gets shifted 8 places. The 4th byte does not get shifted. The 4 values are then added.