57. Extract Packet Fields from Byte Stream

You receive a 6-byte data packet from a peripheral interface (e.g., UART or I2C). The byte stream format is:

Byte IndexFieldSize
0start1
1command1
2–3data2
4crc1
5end1

You are given the packet as an array: uint8_t buffer[6]. Your task is to extract and print each field as integer values
 

Example-1

Input: 165 1 52 18 119 90
Output:
Start: 165
Command: 1
Data: 4660
CRC: 119
End: 90

 

Example-2

Input: 170 255 255 0 254 85
Output:
Start: 170
Command: 255
Data: 255
CRC: 254
End: 85


 

Loading...

Input

165 1 52 18 119 90

Expected Output

Start: 165 Command: 1 Data: 4660 CRC: 119 End: 90