[vtkusers] #Defines for Big or Little Endian
Mike Jackson
imikejackson at gmail.com
Fri Sep 1 08:39:05 EDT 2006
Actually,
Apple has this exact set of methods in their open source Core Foundation
code.
So for example they have:
vtkTypeUInt32 CFSwapInt32BigToHost(vtkTypeUInt32 arg)
{
#if defined(__BIG_ENDIAN__)
return arg;
#else
return CFSwapInt32(arg);
#endif
}
vtkTypeUInt32 CFSwapInt32(vtkTypeUInt32 arg) {
#if defined(__i386__) && defined(__GNUC__)
__asm__("bswap %0" : "+r" (arg));
return arg;
#elif defined(__ppc__) && defined(__GNUC__)
vtkTypeUInt32 result;
__asm__("lwbrx %0,0,%1" : "=r" (result) : "r" (&arg), "m" (arg));
return result;
#else
vtkTypeUInt32 result;
result = ((arg & 0xFF) << 24) | ((arg & 0xFF00) << 8) | ((arg >> 8) &
0xFF00) | ((arg >> 24) & 0xFF);
return result;
#endif
}
This is basically what I am looking for.
Thanks for all those that replied with help.
Mike Jackson
On 9/1/06 7:24 AM, "Bob Palank" <bob at stlcc.org> wrote:
> Why not write the integer(s) to disk and then use a Hex editor to inspect
> the file ?
> ByteViewer works for me.
> BR
> Bob
>
> -----Original Message-----
> From: vtkusers-bounces+bob=stlcc.org at vtk.org
> [mailto:vtkusers-bounces+bob=stlcc.org at vtk.org]On Behalf Of Mike Jackson
> Sent: Thursday, August 31, 2006 3:36 PM
> To: VTK Users
> Subject: [vtkusers] #Defines for Big or Little Endian
>
>
> Is there a #define some where that I can use to test if I am running
> on a big or little endian machine?
>
> Beyond that, are there already methods some where that I have not
> found that will take a value, say UIn32 and swap the bytes to whatever
> the system is? Something like:
>
> ByteSwap::swapLEToSystem( UInt32 );
>
> Thanks
>
> --
> Mike Jackson
> imikejackson _at_ gee-mail dot com
> _______________________________________________
More information about the vtkusers
mailing list