1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #include <iostream>
15 
log2(int n)16 static inline int log2( int n )
17 {
18   int bits = 0;
19   while (n > 0)
20     {
21     bits++;
22     n >>= 1;
23     }
24   return bits;
25 }
26 
TestLog2(int,char * [])27 int TestLog2(int , char *[])
28 {
29   int v;
30   v = log2(255);
31   if( v != 8 ) return 1;
32   v = log2(256);
33   if( v != 9 ) return 1;
34   v = log2(4095);
35   if( v != 12 ) return 1;
36   v = log2(4096);
37   if( v != 13 ) return 1;
38 
39   return 0;
40 }
41