equal
deleted
inserted
replaced
|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Utility functions for the Mass Storage file system. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32std_private.h> |
|
25 |
|
26 /** |
|
27 Returns ETrue if aNum is a power of two |
|
28 */ |
|
29 GLDEF_C TBool IsPowerOfTwo(TInt aNum) |
|
30 { |
|
31 |
|
32 if (aNum==0) |
|
33 return(EFalse); |
|
34 |
|
35 while(aNum) |
|
36 { |
|
37 if (aNum & 0x01) |
|
38 { |
|
39 if (aNum>>1) |
|
40 return EFalse; |
|
41 break; |
|
42 } |
|
43 aNum>>=1; |
|
44 } |
|
45 return ETrue; |
|
46 } |
|
47 |
|
48 /** |
|
49 Returns the position of the highest bit in aNum or -1 if aNum == 0 |
|
50 */ |
|
51 GLDEF_C TInt Log2(TInt aNum) |
|
52 { |
|
53 |
|
54 TInt res=-1; |
|
55 while(aNum) |
|
56 { |
|
57 res++; |
|
58 aNum>>=1; |
|
59 } |
|
60 return(res); |
|
61 } |
|
62 |