Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Using cout to print hex values; surely you can't be serious Date: Thu, 09 Feb 2012 21:44:47 +1300 Lines: 20 Message-ID: <9phfbvF8slU1@mid.individual.net> References: <08081227-b09b-454f-b23d-85ebb98207c0@n12g2000yqb.googlegroups.com> <9phagoFom1U7@mid.individual.net> <0684f226-3bfc-46a7-8581-ce345da2be4e@b18g2000vbz.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net rOf1FcT16x/R2Ar3C4kxyghcjqz8rmw/Ue4EibwjE++e0asfT2 Cancel-Lock: sha1:EHt3maK9gcbTH6W5yE7PTWqaqzM= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2 In-Reply-To: <0684f226-3bfc-46a7-8581-ce345da2be4e@b18g2000vbz.googlegroups.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:13866 On 02/ 9/12 09:16 PM, gwowen wrote: > On Feb 9, 7:22 am, Ian Collins wrote: >>> If you are afraid that char is 32 or 64 bits on some platform and might not >>> fit into the buffer, you can make the buffer e.g. 17 bytes long as a >>> precaution. >> >> The buffer is an array of char, so it will always be big enough no >> matter how big a char is (in c++ terms it is always 1). > > A char value bigger than 255 will need three (or more) char's to hold > its ascii hex representation. No matter how big a char is, once > you're representing it as an ASCII sequence of 0-9A-F, you're going to > need a string of length ~ log_16(CHAR_MAX). Just like you need 3 > bytes to hold the ascii decimal representation of an 8-bit char now, " > 0"-"255" Don't forget the the format string was "%02X".. -- Ian Collins