ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2011/09/10/09:45:15

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Mok-Kong Shen <mok-kong DOT shen AT t-online DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: A printf problem?
Date: Sat, 10 Sep 2011 15:37:09 +0200
Organization: albasani.net
Lines: 30
Message-ID: <j4fp2e$ksp$1@news.albasani.net>
Mime-Version: 1.0
X-Trace: news.albasani.net V4y8yzTVJ9iEqzIyl4kxDc9CafxCsNPPPGCQyjlGTyJgDDXGsoHQIVYL9U3wKkjqggYdlL+VbfYvTr/j4AzZ6A==
NNTP-Posting-Date: Sat, 10 Sep 2011 13:35:10 +0000 (UTC)
Injection-Info: news.albasani.net; logging-data="6+5iLi1Cn0if9AjjBwILCa9ril5Z2Vstd00iIeEXWuTpMKIvqL66cv8iXTRMNSEmbnqK+ChhoNzdsvy5lDgYdkx33TSBLCaKeSTcyOJVEJAs6TJhPzVIbSDrrYVG7GCm"; mail-complaints-to="abuse AT albasani DOT net"
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2
Cancel-Lock: sha1:JCKX/Qqy9R9AFNPcNDncWXpurnw=
Bytes: 1795
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

Maybe I have made a very grave mistake, but I just can't yet understand
why the code attached below produced the following output:

first:      cc22       55258
second:     d7da       55258
third:      ffff       65535

Why are the first two numbers, which are different hexadecimals,
printed out as the same decimal number?

Thanks for your kind help in advance.

M. K. Shen

------------------------------------------------------
#include <stdio.h>

int main()
{ unsigned long int g;

   g=0xcc22; printf("first:  %8x  %10lu\n",g,g);

   g=0xd7da; printf("second: %8x  %10lu\n",g,g);

   g=0xffff; printf("third:  %8x  %10lu\n",g,g);

   return(0);
}

- Raw text -


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