delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/10/05/17:45:32

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: displaying numbers in hexadecimal
Date: Sat, 05 Oct 2002 18:31:56 +0100
Lines: 21
Message-ID: <3D9F220C.EEC5F@phekda.freeserve.co.uk>
References: <CjCn9.3111$bx2 DOT 249693279 AT newssvr12 DOT news DOT prodigy DOT com>
NNTP-Posting-Host: 62.136.65.32
Mime-Version: 1.0
X-Trace: news5.svr.pol.co.uk 1033854236 17870 62.136.65.32 (5 Oct 2002 21:43:56 GMT)
NNTP-Posting-Date: 5 Oct 2002 21:43:56 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586)
X-Accept-Language: de,fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello.

John Smth wrote:
> How can i get my program to display a number in hexadecimal form? For
> example, in my program i have a line cout << 0x9 + 0x2 << "\n";
> the output is 11, but i need t to be 'B'. It was suggested to me to add
> '<<hex<< to the line but the compiler didnt recognize the 'hex' command.

Try:

    cout << hex << (0x9 + 0x2) << endl;

You may want to switch the default number format back to decimal, after
switching it to hexidecimal:

    cout << hex << (0x9 + 0x2) << dec << endl;

HTH. Regards,

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019