Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : P words : power.
![]() | The Art of Computer Programming Volume 2 Seminumerical Algorithms, Third Edition. | ||||||
| 0-201-48541-9 | |||||||
| Donald Knuth | |||||||
| |||||||
Here is a fast integer log2 approximation:
/** * fast integer log2 approximation. * @param n number to take log2 of, n >= 5. * @return 8 * (log2( n ) - 1 ) */ public static int bitLog( int n ) { if ( n <= 8 ) { return 2 * n; } else { int b = 31; while ( b > 2 && n > 0 ) { b--; n <<= 1; } n &= 0x70000000; n >>= 28; return n + 8 *( b - 1 ); } } // end bitLog
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 3130. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/power.html | J:\mindprod\jgloss\power.html | |||