array.h (3774B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2008 Jef Driesen 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301 USA 20 */ 21 22 #ifndef ARRAY_H 23 #define ARRAY_H 24 25 #define C_ARRAY_SIZE(a) (sizeof (a) / sizeof *(a)) 26 #define C_ARRAY_ITEMSIZE(a) (sizeof *(a)) 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif /* __cplusplus */ 31 32 void 33 array_reverse_bytes (unsigned char data[], unsigned int size); 34 35 void 36 array_reverse_bits (unsigned char data[], unsigned int size); 37 38 void 39 array_reverse_nibbles (unsigned char data[], unsigned int size); 40 41 int 42 array_isequal (const unsigned char data[], unsigned int size, unsigned char value); 43 44 const unsigned char * 45 array_search_forward (const unsigned char *data, unsigned int size, 46 const unsigned char *marker, unsigned int msize); 47 48 const unsigned char * 49 array_search_backward (const unsigned char *data, unsigned int size, 50 const unsigned char *marker, unsigned int msize); 51 52 int 53 array_convert_bin2hex (const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize); 54 55 int 56 array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize); 57 58 unsigned int 59 array_convert_str2num (const unsigned char data[], unsigned int size); 60 61 unsigned int 62 array_convert_bin2dec (const unsigned char data[], unsigned int size); 63 64 unsigned int 65 array_convert_bcd2dec (const unsigned char data[], unsigned int size); 66 67 unsigned int 68 array_uint_be (const unsigned char data[], unsigned int n); 69 70 unsigned int 71 array_uint_le (const unsigned char data[], unsigned int n); 72 73 unsigned long long 74 array_uint64_be (const unsigned char data[]); 75 76 unsigned long long 77 array_uint64_le (const unsigned char data[]); 78 79 unsigned int 80 array_uint32_be (const unsigned char data[]); 81 82 unsigned int 83 array_uint32_le (const unsigned char data[]); 84 85 unsigned int 86 array_uint32_word_be (const unsigned char data[]); 87 88 unsigned int 89 array_uint24_be (const unsigned char data[]); 90 91 unsigned int 92 array_uint24_le (const unsigned char data[]); 93 94 unsigned short 95 array_uint16_be (const unsigned char data[]); 96 97 unsigned short 98 array_uint16_le (const unsigned char data[]); 99 100 float 101 array_float_le (const unsigned char data[]); 102 103 void 104 array_uint64_be_set (unsigned char data[], const unsigned long long input); 105 106 void 107 array_uint64_le_set (unsigned char data[], const unsigned long long input); 108 109 void 110 array_uint32_be_set (unsigned char data[], const unsigned int input); 111 112 void 113 array_uint32_le_set (unsigned char data[], const unsigned int input); 114 115 void 116 array_uint24_be_set (unsigned char data[], const unsigned int input); 117 118 void 119 array_uint24_le_set (unsigned char data[], const unsigned int input); 120 121 void 122 array_uint16_be_set (unsigned char data[], const unsigned short input); 123 124 void 125 array_uint16_le_set (unsigned char data[], const unsigned short input); 126 127 unsigned char 128 bcd2dec (unsigned char value); 129 130 unsigned char 131 dec2bcd (unsigned char value); 132 133 unsigned int 134 signextend (unsigned int value, unsigned int nbits); 135 136 unsigned int 137 popcount (unsigned int value); 138 139 #ifdef __cplusplus 140 } 141 #endif /* __cplusplus */ 142 #endif /* ARRAY_H */