1960
|
1 // byte-swap.h -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_byte_swap_h) |
|
25 #define octave_byte_swap_h 1 |
|
26 |
|
27 static inline void |
|
28 swap_bytes (char *t, unsigned int i, unsigned int j) |
|
29 { |
|
30 char tmp = t[i]; |
|
31 t[i] = t[j]; |
|
32 t[j] = tmp; |
|
33 } |
|
34 |
|
35 static inline void |
|
36 swap_2_bytes (char *t) |
|
37 { |
|
38 swap_bytes (t, 0, 1); |
|
39 } |
|
40 |
|
41 static inline void |
|
42 swap_4_bytes (char *t) |
|
43 { |
|
44 swap_bytes (t, 0, 3); |
|
45 swap_bytes (t, 1, 2); |
|
46 } |
|
47 |
|
48 static inline void |
|
49 swap_8_bytes (char *t) |
|
50 { |
|
51 swap_bytes (t, 0, 7); |
|
52 swap_bytes (t, 1, 6); |
|
53 swap_bytes (t, 2, 5); |
|
54 swap_bytes (t, 3, 4); |
|
55 } |
|
56 |
|
57 static inline void |
|
58 swap_2_bytes (char *t, int len) |
|
59 { |
|
60 char *ptr = t; |
|
61 for (int i = 0; i < len; i++) |
|
62 { |
|
63 swap_2_bytes (ptr); |
|
64 ptr += 2; |
|
65 } |
|
66 } |
|
67 |
|
68 static inline void |
|
69 swap_4_bytes (char *t, int len) |
|
70 { |
|
71 char *ptr = t; |
|
72 for (int i = 0; i < len; i++) |
|
73 { |
|
74 swap_4_bytes (ptr); |
|
75 ptr += 4; |
|
76 } |
|
77 } |
|
78 |
|
79 static inline void |
|
80 swap_8_bytes (char *t, int len) |
|
81 { |
|
82 char *ptr = t; |
|
83 for (int i = 0; i < len; i++) |
|
84 { |
|
85 swap_8_bytes (ptr); |
|
86 ptr += 8; |
|
87 } |
|
88 } |
|
89 |
|
90 #endif |
|
91 |
|
92 /* |
|
93 ;;; Local Variables: *** |
|
94 ;;; mode: C++ *** |
|
95 ;;; page-delimiter: "^/\\*" *** |
|
96 ;;; End: *** |
|
97 */ |