Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!texbell!merch!spudge!thorp From: thorp@spudge.UUCP (Don Thorp) Newsgroups: comp.lang.c++ Subject: Understanding base conversions in stream IO Message-ID: <18737@spudge.UUCP> Date: 10 Jul 90 17:40:22 GMT Reply-To: thorp@rwsys.lonestar.org (Don Thorp) Distribution: usa Organization: Friends of Guru Bob Lines: 24 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