"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "eas3pkg/eas3llc/conv.c" of archive eas3pkg_v1.6.3.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /*-------------------------------------------------------------------------------------------------------*/
2 /* EAS3 License */
3 /* */
4 /* Copyright (c) 2006 Institut fuer Aerodynamik und Gasdynamik, Universitaet Stuttgart */
5 /* */
6 /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and */
7 /* associated documentation files (the "Software"), to deal in the Software without restriction, */
8 /* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, */
9 /* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, */
10 /* subject to the following conditions: */
11 /* */
12 /* The above copyright notice and this permission notice shall be included in all copies or substantial */
13 /* portions of the Software. */
14 /* */
15 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT */
16 /* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
17 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
18 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
19 /* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
20 /*-------------------------------------------------------------------------------------------------------*/
21 /* ---------------------------------------------------------
22 * project: eas3llc
23 * file: conv.c
24 * author: Kai Augustin <augustin@iag.uni-stuttgart.de>
25 * Juni 2001
26 * Kai Augustin 03/2002
27 * ---------------------------------------------------------
28 * Hilfsroutinen zur LittleEndian -> BigEndian Konvertierung
29 * auf Intel IA32 und IA64 Maschinen
30 * EAS3 ist generell BigEndian
31 * --------------------------------------------------------- */
32
33 #include <stdlib.h>
34 #include <stdio.h>
35
36 #include "eas3llc.h"
37
38 #ifdef LITTLEENDIAN
39
40 /* 32-bit Konvertierung */
41 Int32 eas3_conv32(size_t numelem, void *in_arr, void *out_arr)
42 {
43 /* 4 Byte types */
44 register Int32 l4 ;
45 Int32 *inarray4, *outarray4 ;
46 /* 4 Byte helpers for byteorder */
47 register Int32 b0,b1,b2,b3 ;
48
49 Int64 i,ilen ;
50
51 inarray4 = (Int32*)in_arr ;
52 outarray4 = (Int32*)out_arr ;
53
54 ilen=(Int64)numelem ;
55
56 #ifdef DEBUG2
57 printf("eas3_conv32(): Function called with %5ld Elements\n",
58 (Int64)numelem) ;
59 #endif
60
61 if (ilen == 0) {
62 #ifdef DEBUG2
63 printf("eas3_conv32(): No elements! Returning.\n") ;
64 #endif
65 return(0) ;
66 }
67
68 for (i=0;i<ilen;i++)
69 {
70 l4 = inarray4[i] ;
71 #ifdef DEBUG2
72 printf("%10.10d:",l4) ;
73 #endif
74 b0 = (l4 & 0x000000ff) << 24 ;
75 b1 = (l4 & 0x0000ff00) << 8 ;
76 b2 = (l4 & 0x00ff0000) >> 8 ;
77 b3 = (l4 & 0xff000000) >> 24 ;
78 l4 = 0 ;
79 l4 = b0|b1|b2|b3 ;
80 #ifdef DEBUG_2
81 printf("%10.10d ",l4) ;
82 #endif
83 outarray4[i] = l4 ;
84 }
85 #ifdef DEBUG2
86 printf("\neas3_conv32(): Conversion completed\n",
87 (Int64)numelem) ;
88 #endif
89 return(0) ;
90 }
91
92 /* 64-bit Konvertierung */
93 Int32 eas3_conv64(size_t numelem, void *in_arr, void *out_arr)
94 {
95
96 /* 8 Byte types */
97 register Int64 l8 ;
98 Int64 *inarray8, *outarray8 ;
99 /* 4 Byte helpers for byteorder */
100 register Int64 b0,b1,b2,b3,b4,b5,b6,b7 ;
101
102 Int64 i,ilen ;
103
104 inarray8 = (Int64*)in_arr ;
105 outarray8 = (Int64*)out_arr ;
106
107 ilen=(Int64)numelem ;
108
109 #ifdef DEBUG2
110 printf("eas3_conv64(): Function called with %5ld Elements\n",
111 (Int64)numelem) ;
112 #endif
113
114 if (ilen == 0)
115 {
116 #ifdef DEBUG2
117 printf("eas3_conv64(): No elements! Returning.\n") ;
118 #endif
119 return(0) ;
120 }
121
122 for (i=0;i<ilen;i++)
123 {
124 l8=inarray8[i] ;
125 #ifdef DEBUG2
126 printf("%20.20ld:",l8) ;
127 #endif
128 b0 = (l8 & 0x00000000000000ff) << 56 ;
129 b1 = (l8 & 0x000000000000ff00) << 40 ;
130 b2 = (l8 & 0x0000000000ff0000) << 24 ;
131 b3 = (l8 & 0x00000000ff000000) << 8 ;
132 b4 = (l8 & 0x000000ff00000000) >> 8 ;
133 b5 = (l8 & 0x0000ff0000000000) >> 24 ;
134 b6 = (l8 & 0x00ff000000000000) >> 40 ;
135 b7 = (l8 & 0xff00000000000000) >> 56 ;
136 l8=0 ;
137 l8 = b0|b1|b2|b3|b4|b5|b6|b7 ;
138 #ifdef DEBUG2
139 printf("%20.20ld ",l8) ;
140 #endif
141 outarray8[i] = l8 ;
142 }
143
144 #ifdef DEBUG2
145 printf("\neas3_conv64(): Conversion completed\n",
146 (Int64)numelem) ;
147 #endif
148
149 return(0) ;
150 }
151 #endif /* LITTLEENDIAN */