1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file defines some bit utilities.
10 #include "base/basictypes.h"
11 #include "base/logging.h"
16 // Returns the integer i such as 2^i <= n < 2^(i+1)
17 inline int Log2Floor(uint32 n
) {
22 for (int i
= 4; i
>= 0; --i
) {
24 uint32 x
= value
>> shift
;
34 // Returns the integer i such as 2^(i-1) < n <= 2^i
35 inline int Log2Ceiling(uint32 n
) {
39 // Log2Floor returns -1 for 0, so the following works correctly for n=1.
40 return 1 + Log2Floor(n
- 1);
47 #endif // BASE_BITS_H_