1 /* integer_length - find most significant bit in an unsigned integer.
2 Copyright (C) 2011-2019 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
19 #ifndef _INTEGER_LENGTH_H
20 #define _INTEGER_LENGTH_H
26 /* These functions return the minimum number of bits required to represent
27 the given unsigned integer.
28 For non-zero values, this is the position of the most significant bit
29 that is set, plus one. For zero, it is 0. */
31 /* Returns the integer length of x.
32 The result is >= 0, <= sizeof (unsigned int) * CHAR_BIT. */
33 extern int integer_length (unsigned int x
);
35 /* Returns the integer length of x.
36 The result is >= 0, <= sizeof (unsigned long) * CHAR_BIT. */
37 extern int integer_length_l (unsigned long x
);
39 #if HAVE_UNSIGNED_LONG_LONG_INT
40 /* Returns the integer length of x.
41 The result is >= 0, <= sizeof (unsigned long long) * CHAR_BIT. */
42 extern int integer_length_ll (unsigned long long x
);
49 #endif /* _INTEGER_LENGTH_H */