2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)intcvt.h 1.4 03/12/29 Copyright 1986-2003 J. Schilling */
15 * Definitions for conversion to/from integer data types of various size.
17 * Copyright (c) 1986-2003 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #define i_to_2_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 8) & 0xFF,\
42 ((Uchar *)(a))[1] = (i) & 0xFF)
44 #define i_to_3_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 16)& 0xFF,\
45 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\
46 ((Uchar *)(a))[2] = (i) & 0xFF)
48 #define i_to_4_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 24)& 0xFF,\
49 ((Uchar *)(a))[1] = ((i) >> 16)& 0xFF,\
50 ((Uchar *)(a))[2] = ((i) >> 8) & 0xFF,\
51 ((Uchar *)(a))[3] = (i) & 0xFF)
55 #define a_to_byte(a) (((Int8_t *) a)[0])
57 #define a_to_u_byte(a) ((UInt8_t) \
58 (((Uchar *) a)[0] & 0xFF))
60 #define a_to_u_2_byte(a) ((UInt16_t) \
61 ((((Uchar *) a)[1] & 0xFF) | \
62 (((Uchar *) a)[0] << 8 & 0xFF00)))
64 #define a_to_2_byte(a) (int)(Int16_t)a_to_u_2_byte(a)
66 #define a_to_u_3_byte(a) ((Ulong) \
67 ((((Uchar *) a)[2] & 0xFF) | \
68 (((Uchar *) a)[1] << 8 & 0xFF00) | \
69 (((Uchar *) a)[0] << 16 & 0xFF0000)))
71 #define a_to_3_byte(a) a_to_u_3_byte(a) /* XXX Is there a signed version ? */
74 # define __TOP_4BYTE 0xFF000000UL
76 # define __TOP_4BYTE 0xFF000000
79 #define a_to_u_4_byte(a) ((Ulong) \
80 ((((Uchar*) a)[3] & 0xFF) | \
81 (((Uchar*) a)[2] << 8 & 0xFF00) | \
82 (((Uchar*) a)[1] << 16 & 0xFF0000) | \
83 (((Uchar*) a)[0] << 24 & __TOP_4BYTE)))
85 #define a_to_4_byte(a) (long)(Int32_t)a_to_u_4_byte(a)
88 * Little Endian versions of above macros
90 #define li_to_2_byte(a, i) (((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\
91 ((Uchar *)(a))[0] = (i) & 0xFF)
93 #define li_to_3_byte(a, i) (((Uchar *)(a))[2] = ((i) >> 16)& 0xFF,\
94 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\
95 ((Uchar *)(a))[0] = (i) & 0xFF)
97 #define li_to_4_byte(a, i) (((Uchar *)(a))[3] = ((i) >> 24)& 0xFF,\
98 ((Uchar *)(a))[2] = ((i) >> 16)& 0xFF,\
99 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\
100 ((Uchar *)(a))[0] = (i) & 0xFF)
103 #define la_to_u_2_byte(a) ((UInt16_t) \
104 ((((Uchar*) a)[0] & 0xFF) | \
105 (((Uchar*) a)[1] << 8 & 0xFF00)))
107 #define la_to_2_byte(a) (int)(Int16_t)la_to_u_2_byte(a)
109 #define la_to_u_3_byte(a) ((Ulong) \
110 ((((Uchar*) a)[0] & 0xFF) | \
111 (((Uchar*) a)[1] << 8 & 0xFF00) | \
112 (((Uchar*) a)[2] << 16 & 0xFF0000)))
114 #define la_to_3_byte(a) la_to_u_3_byte(a) /* XXX Is there a signed version ? */
116 #define la_to_u_4_byte(a) ((Ulong) \
117 ((((Uchar*) a)[0] & 0xFF) | \
118 (((Uchar*) a)[1] << 8 & 0xFF00) | \
119 (((Uchar*) a)[2] << 16 & 0xFF0000) | \
120 (((Uchar*) a)[3] << 24 & __TOP_4BYTE)))
122 #define la_to_4_byte(a) (long)(Int32_t)la_to_u_4_byte(a)
124 #endif /* _INTCVT_H */