• Advertisement
Sign in to follow this  

From string to long..number in string is hex uho

This topic is 4933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

atof(...) will not return what the number is in hex. Are there any other function in the C Runtime Library that can do this only for hex? If I have to write my own function to do this I will, but I was hoping I wouldnt have to. lol :) example of string: 1A ouput: 1 ?? I guess it just leaves out non-numeric characters should output: 26

Share this post


Link to post
Share on other sites
Advertisement
so far I know there is no standar function to convert a string representation of an hex number into an integer value.

Why do you end up having a hex in a string? are you reading from a textfile?

Share this post


Link to post
Share on other sites
It is a Intel Hex file...I am downloading the EEPROM from a microcontroller and I trying to read/edit the values. It is just a ASCII text file. Are there any 3rd party math libs out there that can do this?

:10000000025E1A1E102700008E4100000B01FFFF48

Share this post


Link to post
Share on other sites
Quote:
Original post by starboarder
:10000000025E1A1E102700008E4100000B01FFFF48


I'm not sure that number will fit into a long... if that's a whole number.

Share this post


Link to post
Share on other sites
strtol in <stdlib.h> taks the base of the number as a parameter. so just pass it 16 and it should parse your number correctly.

Share this post


Link to post
Share on other sites
Quote:
Original post by starboarder
It is a Intel Hex file...I am downloading the EEPROM from a microcontroller and I trying to read/edit the values. It is just a ASCII text file. Are there any 3rd party math libs out there that can do this?

:10000000025E1A1E102700008E4100000B01FFFF48


Tried strtol? It's part of ANSI-C stdlib.

Should work for your case. (You want base 16, or base 0 with "0x" before the number to convert.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement