Groups | Search | Server Info | Login | Register
Groups > comp.lang.c.moderated > #401
| From | Jiří Zárevúcky <zarevucky.jiri@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c.moderated |
| Subject | Re: portable code |
| Date | 2012-05-04 17:30 -0500 |
| Organization | http://groups.google.com |
| Message-ID | <clcm-20120504-0002@plethora.net> (permalink) |
| References | <clcm-20101216-0009@plethora.net> <clcm-20120404-0001@plethora.net> <clcm-20120423-0003@plethora.net> |
On Monday, 23 April 2012 15:31:46 UTC+2, Dag-Erling Smørgrav wrote:
> then the following:
>
> unsigned int i = 0x01020304;
> write((i >> 24) & 0xFF);
> write((i >> 16) & 0xFF);
> write((i >> 8) & 0xFF);
> write(i & 0xFF);
> rewind(f);
> i = 0;
> i += (read() >> 24);
> i += (read() >> 16);
> i += (read() >> 8);
> i += (read());
> printf("i = 0x%x\n", i);
>
> will print
>
> i = 0x4
The snippet has wrong direction of the bit shifts for reads.
Correct would be:
i += (read() << 24);
i += (read() << 16);
i += (read() << 8);
i += (read());
I suspect it's a simple copy-paste error of the original author.
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Next — Previous in thread | Find similar
Re: portable code rangsynth@gmail.com - 2012-04-04 18:05 -0500
Re: portable code Dag-Erling Smørgrav <des@des.no> - 2012-04-23 08:31 -0500
Re: portable code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-30 21:59 -0500
Re: portable code Dag-Erling Smørgrav <des@des.no> - 2012-05-04 17:29 -0500
Re: portable code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-05-09 01:06 -0500
Re: portable code Jiří Zárevúcky <zarevucky.jiri@gmail.com> - 2012-05-04 17:30 -0500
csiph-web