[comp.lang.c++] Understanding base conversions in stream IO

thorp@spudge.UUCP (Don Thorp) (07/11/90)

I have been trying to use C++ streams to read in hex formatted data.  I am
using TC++.  During the course of writing a utility to parse map files, I 
needed to read in hex formated numbers.  After playing around for a while,
I found a bug in TC++ hex conversion routines.  When converting hex digits
a-f only the ones portion of the decimal equivalent was surviving the 
conversion (i.e. 0x1a1 translated to 0x101).  To make a long story short,
what are the valid hexadecimal formats that the stream classes should 
recognize?  TC++ seemed to accept 0xaaaa as well as aaaa although the 
conversion was wrong.  The examples in Lippman only show numbers with
the digits 0-9 as being successfully converted.

  char num[] = "400"
  
  unsigned int val;
  
  strstream(num,sizeof num) >> hex >> val; // gives 0x400
  
If num was changed to a would val equal 0 or 0xA?

------
Don Thorp
  
UUCP     : ...!texbell!rwsys!{spudge|dreamer}!thorp
USENET   : thorp@rwsys.lonestar.org