Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ByteSwap.h

Go to the documentation of this file.
00001 
00002 //
00003 //       Title       : ByteSwap.h
00004 //       Project     : OSCAR
00005 //       Created     : Tue March 24 11:10 A.M. 1998
00006 //       Author      : Chetan Kapoor
00007 //       Platforms   : All
00008 //           Copyright   :  The University of Texas at Austin, 2002. All rights reserved.
00009 //                 
00010 //                 This software and documentation constitute an unpublished work
00011 //                 and contain valuable trade secrets and proprietary information
00012 //                 belonging to University.  None of the foregoing material may be
00013 //                 copied  or duplicated or disclosed without the express, written
00014 //                 permission of University.  UNIVERSITY EXPRESSLY DISCLAIMS ANY
00015 //                 AND ALL WARRANTIES CONCERNING THIS SOFTWARE AND DOCUMENTATION,
00016 //                 INCLUDING ANY WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00017 //                 PARTICULAR PURPOSE, AND WARRANTIES OF PERFORMANCE, AND ANY WARRANTY
00018 //                 THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE.
00019 //                 NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF
00020 //                 THE SOFTWARE OR DOCUMENTATION.  Under no circumstances shall
00021 //                 University be liable for incidental, special, indirect, direct or
00022 //                 consequential damages or loss of profits, interruption of business,
00023 //                 or related expenses which may arise from use of software or documentation,
00024 //                 including but not limited to those resulting from defects in software
00025 //                 and/or documentation, or loss or inaccuracy of data of any kind.
00026 //
00027 //       Purpose     : Utility functions for swapping bytes for transferring
00028 //                         data between different CPU architectures
00029 //----------------------------------------------------------------------------
00030 //
00031 //       Classes:
00032 //
00033 //       Global Functions:
00034 //            int    BByteSwap(int);
00035 //            float  ByteSwap(float);
00036 //            double ByteSwap(double);
00037 //
00038 //       Global Variables:
00039 //               <none>
00040 //
00041 //----------------------------------------------------------------------------
00042 //
00043 //       $Revisions$
00045 
00046 #ifndef ByteSwap_h
00047 #define ByteSwap_h
00048 
00049 #include "Math/Vector.h"
00050 
00051 //class Vector;
00053 namespace OSCAR {
00054 
00055   inline int    ByteSwap(int in)
00056   {
00057      int   retVal;
00058      char* p = (char*)&retVal;
00059      char* i = (char*)&in;
00060      p[0] = i[7];
00061      p[1] = i[6];
00062      p[2] = i[5];
00063      p[3] = i[4];
00064 
00065      return retVal;
00066   }
00067 
00068   inline float  ByteSwap(float in)
00069   {
00070      float retVal;
00071      char* p = (char*)&retVal;
00072      char* i = (char*)&in;
00073      p[0] = i[7];
00074      p[1] = i[6];
00075      p[2] = i[5];
00076      p[3] = i[4];
00077 
00078      return retVal;
00079   }
00080 
00081   inline double ByteSwap(double in)
00082   {
00083      double retVal;
00084      char* p = (char*)&retVal;
00085      char* i = (char*)&in;
00086      p[0] = i[7];
00087      p[1] = i[6];
00088      p[2] = i[5];
00089      p[3] = i[4];
00090 
00091      p[4] = i[3];
00092      p[5] = i[2];
00093      p[6] = i[1];
00094      p[7] = i[0];
00095 
00096      return retVal;
00097   }
00098 
00099   extern void ByteSwap(Vector& v);
00100   extern void ByteSwap(VectorF& v);
00101   extern void ByteSwap(VectorI& v);
00102 
00103 }
00104 #endif
RRG Homepage OSCAR Overview OSCAR Tutorials Simulations