1*d5c9a868SElliott Hughes #ifndef BYTE_DWORD
2*d5c9a868SElliott Hughes #define BYTE_DWORD
3*d5c9a868SElliott Hughes
4*d5c9a868SElliott Hughes /* Copyright 2007,2009 Alain Knaff.
5*d5c9a868SElliott Hughes * This file is part of mtools.
6*d5c9a868SElliott Hughes *
7*d5c9a868SElliott Hughes * Mtools is free software: you can redistribute it and/or modify
8*d5c9a868SElliott Hughes * it under the terms of the GNU General Public License as published by
9*d5c9a868SElliott Hughes * the Free Software Foundation, either version 3 of the License, or
10*d5c9a868SElliott Hughes * (at your option) any later version.
11*d5c9a868SElliott Hughes *
12*d5c9a868SElliott Hughes * Mtools is distributed in the hope that it will be useful,
13*d5c9a868SElliott Hughes * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*d5c9a868SElliott Hughes * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*d5c9a868SElliott Hughes * GNU General Public License for more details.
16*d5c9a868SElliott Hughes *
17*d5c9a868SElliott Hughes * You should have received a copy of the GNU General Public License
18*d5c9a868SElliott Hughes * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
19*d5c9a868SElliott Hughes */
20*d5c9a868SElliott Hughes
byte2dword(Byte * val)21*d5c9a868SElliott Hughes static Dword byte2dword(Byte* val)
22*d5c9a868SElliott Hughes {
23*d5c9a868SElliott Hughes Dword l;
24*d5c9a868SElliott Hughes l = (Dword)((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
25*d5c9a868SElliott Hughes
26*d5c9a868SElliott Hughes return l;
27*d5c9a868SElliott Hughes }
28*d5c9a868SElliott Hughes
UNUSED(static int32_t byte2sdword (Byte * val))29*d5c9a868SElliott Hughes UNUSED(static int32_t byte2sdword(Byte* val))
30*d5c9a868SElliott Hughes {
31*d5c9a868SElliott Hughes int32_t l;
32*d5c9a868SElliott Hughes l = (int32_t)((val[0] << 24) + (val[1] << 16) + (val[2] << 8) + val[3]);
33*d5c9a868SElliott Hughes
34*d5c9a868SElliott Hughes return l;
35*d5c9a868SElliott Hughes }
36*d5c9a868SElliott Hughes
37*d5c9a868SElliott Hughes
UNUSED(static Qword byte2qword (Byte * val))38*d5c9a868SElliott Hughes UNUSED(static Qword byte2qword(Byte* val))
39*d5c9a868SElliott Hughes {
40*d5c9a868SElliott Hughes Qword l;
41*d5c9a868SElliott Hughes l = val[0];
42*d5c9a868SElliott Hughes l = (l << 8) | val[1];
43*d5c9a868SElliott Hughes l = (l << 8) | val[2];
44*d5c9a868SElliott Hughes l = (l << 8) | val[3];
45*d5c9a868SElliott Hughes l = (l << 8) | val[4];
46*d5c9a868SElliott Hughes l = (l << 8) | val[5];
47*d5c9a868SElliott Hughes l = (l << 8) | val[6];
48*d5c9a868SElliott Hughes l = (l << 8) | val[7];
49*d5c9a868SElliott Hughes return l;
50*d5c9a868SElliott Hughes }
51*d5c9a868SElliott Hughes
dword2byte(Dword parm,Byte * rval)52*d5c9a868SElliott Hughes static void dword2byte(Dword parm, Byte* rval)
53*d5c9a868SElliott Hughes {
54*d5c9a868SElliott Hughes rval[0] = (parm >> 24) & 0xff;
55*d5c9a868SElliott Hughes rval[1] = (parm >> 16) & 0xff;
56*d5c9a868SElliott Hughes rval[2] = (parm >> 8) & 0xff;
57*d5c9a868SElliott Hughes rval[3] = parm & 0xff;
58*d5c9a868SElliott Hughes }
59*d5c9a868SElliott Hughes
UNUSED(static void sdword2byte (int32_t parm,Byte * rval))60*d5c9a868SElliott Hughes UNUSED(static void sdword2byte(int32_t parm, Byte* rval))
61*d5c9a868SElliott Hughes {
62*d5c9a868SElliott Hughes rval[0] = (parm >> 24) & 0xff;
63*d5c9a868SElliott Hughes rval[1] = (parm >> 16) & 0xff;
64*d5c9a868SElliott Hughes rval[2] = (parm >> 8) & 0xff;
65*d5c9a868SElliott Hughes rval[3] = parm & 0xff;
66*d5c9a868SElliott Hughes }
67*d5c9a868SElliott Hughes
UNUSED(static void qword2byte (Qword parm,Byte * rval))68*d5c9a868SElliott Hughes UNUSED(static void qword2byte(Qword parm, Byte* rval))
69*d5c9a868SElliott Hughes {
70*d5c9a868SElliott Hughes rval[0] = (parm >> 56) & 0xff;
71*d5c9a868SElliott Hughes rval[1] = (parm >> 48) & 0xff;
72*d5c9a868SElliott Hughes rval[2] = (parm >> 40) & 0xff;
73*d5c9a868SElliott Hughes rval[3] = (parm >> 32) & 0xff;
74*d5c9a868SElliott Hughes rval[4] = (parm >> 24) & 0xff;
75*d5c9a868SElliott Hughes rval[5] = (parm >> 16) & 0xff;
76*d5c9a868SElliott Hughes rval[6] = (parm >> 8) & 0xff;
77*d5c9a868SElliott Hughes rval[7] = parm & 0xff;
78*d5c9a868SElliott Hughes }
79*d5c9a868SElliott Hughes
80*d5c9a868SElliott Hughes #endif
81