you're right, either way it looks like I need some branch statements
to handle the zero case
The algorithm that I use for hex_in is the following:
object Character ch;
object Integer sum;
// start sum at 0
getchar (ch); // ta getchar
while (ch != '\n')
{
sum = sum * 16 + Proper_Digit_Value_Associated_With_Character (ch);
getchar (ch); // ta getchar
}
// sum has the correct value when this loop concludes
Of course, there's a bit of complexity in the conversion handled by my
"call" to Proper_Digit_Value_Associated_With_Character, but I claim that
this algorithm does the job correctly.
It will even handle the input string "0000001a\n" correctly. Object sum
remains at zero until the character '1' is encountered, then it becomes
1 before being multiplied by 16 to become sixteen; then ten is added to
it to make it 26 (in other words, 0x1A).
--
Wayne