It looks like you're new here. If you want to get involved, click one of these buttons!
Subscribe to our Patreon, and get image uploads with no ads on the site!
Base theme by DesignModo & ported to Powered by Vanilla by Chris Ireland, modified by the "theFB" team.
Comments
Seriously: If you value it, take/fetch it yourself
I'd be inclined to initialise result to -1 or 255 rather than 0. As it stands, that routine would return a valid value (zero) if it was passed garbage. The calling routine could validate what it passes (by doing the same sort of filtering as is done in HexCharToInt), but checking the return value would be less code.
Nomad
Nobody loves me but my mother... and she could be jivin' too...
Otherwise it breaks at anything over F.
To do that would be a bit more complex, though. It would (not a coder so bear with me) need:
a function to convert each element of the string.
a function to compile the data into columnar data to approximate the units/tens/hundreds columns in decimal from the 15s, 225s etc.
a function to calculate down the columns to aggregate the result of the string.
I bet there's a header library for that in Linux.
Seriously: If you value it, take/fetch it yourself
Offset "(Emp) - a little heavy on the hyperbole."
You don't need to worry about the separate decimal digits at all if doing it by hand either, just sum up the converted hex values with their appropriate powers of 16. I had to check, but that actually works (A-F is contiguous, the whole alphabet is not), I just used to hang out on alt.lang.c and got paranoid about character sets. It's not guaranteed to work (only the decimal digits trick is) but requires something worse than EBCDIC to break it.
Seriously: If you value it, take/fetch it yourself