Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Convert data to hexadecimal packets

Status
Not open for further replies.

saddieop

Newbie
Joined
Jan 18, 2023
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
10
I am new to embedded c programming and I want to know how I can convert arrays into hexadecimal packets to send it over serial.

These are my arrays :
uint8 array_1[5] = {23, 45, 67, 89, 33};
uint8 array_2[5] = {46, 78, 93, 49, 20};

Thanks!
A
 

Hi,

uint8 means it is an unsigned 8 bit integer value. It is a byte. The range is from 0 to 255 (decimal)

Decimal, hexadecimal, ASCII .... all are just representations of one byte. Thus there is no need to convert it for transmitting.

Example: With uint8
65 (decimal) = 0x41 (Hex) = 'A' (ASCII).
--> It all is the same value, but with a different representation.

So your array:
* uint8 array_1[5] = {23, 45, 67, 89, 33};
* is axactly the same as: uint8 array_1[5] = {23, 0x2D, 'C', 'Y', 0x21);

Klaus
 

...or, as data is already 8-bit wide, just step through the array in a loop and send the contents to the serial port. No conversion is needed. If it has to be converted to text so for example 23 has to be sent as characters '2' then '3' instead of binary 00010111 then convert it to a text string using sprintf then send each character of the string at a time.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top