From: wwp <subscript@free.fr>
To: linux-c-programming@vger.kernel.org
Cc: mailing-lists@xs4all.nl
Subject: Re: printf format type, precision...
Date: Sat, 3 Jul 2004 01:19:23 +0200 [thread overview]
Message-ID: <20040703011923.4641036a@tethys.solarsys.org> (raw)
In-Reply-To: <Pine.LNX.4.21.0407030018090.1619-100000@hestia>
Hello J.,
On Sat, 3 Jul 2004 00:32:27 +0200 (CEST) "J." <mailing-lists@xs4all.nl> wrote:
> Saturday, July 03 00:18:09
>
> Hello,
>
> I am trying to convert an IP address to it's eq. in base10
> [homework]. However the outcome from the formula listed below isn't giving
> me the right results. Is this because I'm using the wrong precision type
> for the `result' variable ? If that's the case what other precision type
> should I use instead ? Right now I can't see the format tree's trhu the
> precision forrest anmore .. ehum.
See if the following gives what you expect. Please not the () around the <<
operation, try w/o them (you'll see the difference about operator precedence).
#include <stdio.h>
int main(void) {
int var1 = 192;
int var2 = 168;
int var3 = 1;
int var4 = 10;
long unsigned int result = 0;
result = (var1 << 24) + (var2 << 16) + (var3 << 8) + var4;
printf("%lu %0lx\n", result, result);
return 0;
}
Regards,
--
wwp
next prev parent reply other threads:[~2004-07-02 23:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-02 22:32 printf format type, precision J.
2004-07-02 23:10 ` wwp
2004-07-02 23:29 ` J.
2004-07-02 23:11 ` Glynn Clements
2004-07-02 23:19 ` wwp [this message]
2004-07-02 23:36 ` printf format type, precision... Solved J.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040703011923.4641036a@tethys.solarsys.org \
--to=subscript@free.fr \
--cc=linux-c-programming@vger.kernel.org \
--cc=mailing-lists@xs4all.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).