Article View: borland.public.cppbuilder.nativeapi
Article #9476Re: Big, Little and Bi endians
From: Andrue Cope [TeamB]
Date: Fri, 09 Jul 2004 10:21
Date: Fri, 09 Jul 2004 10:21
33 lines
1881 bytes
1881 bytes
<Donut> wrote: > How to check in C++ program if our applciation running on a > Big/Little/Bi Endian machine? There may be a clever way of doing it but I'd use: WORD binkle=0x1234; bool IAmBigEndian=( *reinterpret_cast<BYTE *>( &binkle )==0x12 ); > Is there a generic way of transforming data (which could be in any > structure) between different endians? Sortof. You can't easily convert any /structure/ as you'd need to know the structures layout (the conversion has to be done field by field) but you can fairly easily write a template function to convert any numeric value. Mostly it's either big- or little- so all you have to do is swap the bytes around. Unfortunately I believe that a third format exists and might actually be supported by Intel hardware. Years ago when looking at a unix file system I came across DWORDs stored as: <big word><little word> Where each word was <little byte><big byte>. ..but I've not seen this recently. -- Andrue Cope [TeamB] [Bicester, Uk] http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<40ee71ab$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40ee62ed$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e4fd0ef684fef580 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@spammy.com> Subject: Re: Big, Little and Bi endians Newsgroups: borland.public.cppbuilder.nativeapi References: <40ee62ed$1@newsgroups.borland.com> User-Agent: XanaNews/1.16.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <40ee71ab$1@newsgroups.borland.com> Date: 9 Jul 2004 03:21:31 -0700 X-Trace: newsgroups.borland.com 1089368491 217.207.223.34 (9 Jul 2004 03:21:31 -0700) Lines: 33 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail