Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Endian.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 /* endian.c */
00025 
00026 #include "machine.h"
00027 #include "Endian.h"
00028 
00029 #ifdef MACHINE_ENDIAN_LITTLE
00030 
00031 #ifndef ENDIAN_MACRO
00032 u32 endian_ToAlien32(u32 v)
00033 {
00034   u32 ret=0L;
00035 
00036   // little->big
00037   ret=(v>>24)|((v>>16)&0xff)|((v>>8)&0xff)|(v&0xff);
00038 
00039   return(ret);
00040 }
00041 
00042 u32 endian_FromAlien32(u32 v)
00043 {
00044   u32 ret=0L;
00045 
00046   // big->little
00047   ret=(v>>24)|((v>>16)&0xff)|((v>>8)&0xff)|(v&0xff);
00048 
00049   return(ret);
00050 }
00051 
00052 u16 endian_ToAlien16(u32 v)
00053 {
00054   u16 ret=0L;
00055 
00056   // little->big
00057   ret=((v>>8)|(v&0xff);
00058 
00059   return(ret);
00060 }
00061 
00062 u16 endian_FromAlien16(u16 v)
00063 {
00064   u16 ret=0L;
00065 
00066   // big->little
00067   ret=((v>>8)|(v&0xff);
00068 
00069   return(ret);
00070 }
00071 #endif
00072 
00073 #endif
00074 
00076 
00077 #ifdef MACHINE_ENDIAN_BIG
00078 
00079 u32 endian_ToAlien32(u32 v)
00080 {
00081   u32 ret=0L;
00082 
00083   // big->little
00084   ret=(v>>24)|((v>>16)&0xff)|((v>>8)&0xff)|(v&0xff);
00085 
00086   return(ret);
00087 }
00088 
00089 u32 endian_FromAlien32(u32 v)
00090 {
00091   u32 ret=0L;
00092 
00093   // little->big
00094   ret=(v>>24)|((v>>16)&0xff)|((v>>8)&0xff)|(v&0xff);
00095 
00096   return(ret);
00097 }
00098 
00099 u16 endian_ToAlien16(u32 v)
00100 {
00101   u16 ret=0L;
00102 
00103   // big->little
00104   ret=((v>>8)|(v&0xff);
00105 
00106   return(ret);
00107 }
00108 
00109 u16 endian_FromAlien16(u16 v)
00110 {
00111   u16 ret=0L;
00112 
00113   // little->big
00114   ret=((v>>8)|(v&0xff);
00115 
00116   return(ret);
00117 }
00118 
00119 #endif

Generated on Tue Jan 7 12:11:18 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002