Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the code comment 'HD, Figure' mean in Java java.lang.Integer class?

for example, the JDK method java.lang.Integer.numberOfLeadingZeros(int):

public static int numberOfLeadingZeros(int i) {
    // HD, Figure 5-6
    if (i == 0)
        return 32;
    int n = 1;
    if (i >>> 16 == 0) { n += 16; i <<= 16; }
    if (i >>> 24 == 0) { n +=  8; i <<=  8; }
    if (i >>> 28 == 0) { n +=  4; i <<=  4; }
    if (i >>> 30 == 0) { n +=  2; i <<=  2; }
    n -= i >>> 31;
    return n;
}

what does the code comment 'HD, Figure 5-6' mean?

like image 262
Jason Avatar asked Mar 08 '23 20:03

Jason


1 Answers

HD = Hacker's Delight. See the the javadoc:

Implementation note: The implementations of the "bit twiddling" methods (such as highestOneBit and numberOfTrailingZeros) are based on material from Henry S. Warren, Jr.'s Hacker's Delight, (Addison Wesley, 2002).

like image 155
assylias Avatar answered Mar 10 '23 09:03

assylias