The first parameter is the string to be converted.
The second is a pointer to a char*. It points to the character after the last character converted. If you're not using it then just put in a dummy variable.
The third parameter is the base, which, in your case, will be 16.
Just to clarify, in drewdaman's pseudo code, "16^j" means "16 to the power of j" not "16 xor j"
^ means "exclusive or" in C/C++
^ means pointer in Pascal
^ means "to the power of" in some languages (the last one I used that had this notation was Algol 68!)
Oh, never use pow() function in that case! Better use a simple shift (<<4 for accumulated result). get value of char at i from enum - sound mysterious and ambiguous...
ps. as for the enumeration... i don't really remember the syntax for it.. but if you have an enum
hexdigits={0,1,2,3,4,5,6,7,8,9,10,A,B,C,D,E,F}
there must be a way to figure out the position a certain character is at in the enumeration...
i know you can do:
days={sun, mon, tues, .., etc}
and sun=1, mon=2 etc.
maybe the reverse is possible? i haven't used enums in a long time.. so i can't remember... but the point was that you should map the hex digit to a decimal digit some how. the enum was just a suggestion...
The pow() function is too expensive: floating point calculations with exp and log (). We have integral type data and powers of 16 in the case above.
So using pow() == nuclear strike against a petty thief.
a homebrew fragile algorithm that half-works is simple (obviously! haha) but the CORRECT algorithm that works across character sets is in the library functions strtol() and strtoul().
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.