From: Damian Yerrick Newsgroups: comp.os.msdos.djgpp Subject: Re: big-endian and little endian binaries Organization: Pin Eight Software Message-ID: References: <85reog$bqi$1 AT plato DOT harvard DOT edu> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 44 X-Trace: +rnM+kGtrlzqVBT8OCOAiID4SJbhbMkXHGdEJpbLc50nj1LlnTE3ANBIAY2+Us/ZNolnjEUVg3Pc!unbtmesu5oYMXNrlPeNWUb498UAK282XIEfBOqY9S727mF5m7csLwiOvUovqWpsAvWQmpmBwmA== X-Complaints-To: abuse AT gte DOT net X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly NNTP-Posting-Date: Sun, 16 Jan 2000 03:58:42 GMT Distribution: world Date: Sun, 16 Jan 2000 03:58:42 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Greg Wellenius" wrote in message <85reog$bqi$1 AT plato DOT harvard DOT edu>... >Hello, > >Any ideas on how, in C++, I might be able to write big-endian numbers >(2-byte ints in this case) to a binary file when I'm on a machine that uses >little-endian format? You could start with these: /* fputbe2i() * write a big-endian (Motorola) 2-byte integer to a file */ int fputbe2i(FILE *fp, short n) { fputc((n >> 8) & 0xff, fp); fputc((n ) & 0xff, fp); } /* fputbe4i() * write a big-endian (Motorola) 4-byte integer to a file */ int fputbe4i(FILE *fp, int n) { fputc((n >> 24) & 0xff, fp); fputc((n >> 16) & 0xff, fp); fputc((n >> 8) & 0xff, fp); fputc((n ) & 0xff, fp); } I know I may be reinventing the wheel, but I couldn't find anything of the sort in info libc. -- Damian Yerrick http://yerricde.tripod.com/ View full sig at http://www.rose-hulman.edu/~yerricde/sig.html Comment on story ideas at http://home1.gte.net/frodo/quickjot.html And yes, I have set my attribute line to emulate Outhouse Express.