CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

String to Hex number

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Freddie



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

String to Hex number
PostPosted: Wed Jun 20, 2007 10:37 am     Reply with quote

Using Compiler PCM 3.242, PIC 16F877.

I have a string of variable length that is received from another device via serial port in the following format (without quotes)

"data7E3B99D7"

After the word data, I need to extract each 2 characters into an int8 array as follows:
mydata[0] = 0x7E
mydata[1] = 0x3B
mydata[2] = 0x99
mydata[3] = 0xD7

Can someone give me a piece of code that can convert the string data into hex numbers and put them in this array?

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 2:30 pm     Reply with quote

To extract 2-byte strings, you could use the the method shown
in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=27121

To convert the 2-byte strings to integer values:
http://www.ccsinfo.com/forum/viewtopic.php?p=70543
Guest








PostPosted: Thu Jun 21, 2007 5:59 am     Reply with quote

These look like exactly what I need. I'll try them today. Thanks PCM Programmer!!
Freddie



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu Jun 21, 2007 5:19 pm     Reply with quote

Works perfect. Thanks PCM programmer.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group