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

Started by
6 comments, last by starboarder 19 years, 5 months ago
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
- - - - - - - - - - - - - - - -www.Vision-Software.org
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?
[size="2"]I like the Walrus best.
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
- - - - - - - - - - - - - - - -www.Vision-Software.org
Quote:Original post by starboarder
:10000000025E1A1E102700008E4100000B01FFFF48


I'm not sure that number will fit into a long... if that's a whole number.
[size="2"]I like the Walrus best.
nahh..that is the whole EEPROM.
The first byte:02 is the version of my firmware.
The next word:5E1A is the dwell setting.
etc
- - - - - - - - - - - - - - - -www.Vision-Software.org
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.
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.)
nope...I have never used strtol(...) before. Thanks allot I got it working now! :)
- - - - - - - - - - - - - - - -www.Vision-Software.org

This topic is closed to new replies.

Advertisement