gpt4 book ai didi

java - Java 类 Integer 和 Long 的源代码中的 "HD"是什么意思?

转载 作者:搜寻专家 更新时间:2023-11-01 01:27:26 25 4
gpt4 key购买 nike

在 Integer.java 和 Long.java 的源代码中,在大多数位旋转方法中,有一个对称为“HD”的东西的注释引用。每个方法都指向所述引用的特定部分。

那个引用是什么?


下面是 Integer 类的方法 highestOneBit(int) 中的示例(源代码 here,第 1035 行):

/**
* Returns an {@code int} value with at most a single one-bit, in the
* position of the highest-order ("leftmost") one-bit in the specified
* {@code int} value. Returns zero if the specified value has no
* one-bits in its two's complement binary representation, that is, if it
* is equal to zero.
*
* @return an {@code int} value with a single one-bit, in the position
* of the highest-order one-bit in the specified value, or zero if
* the specified value is itself equal to zero.
* @since 1.5
*/
public static int highestOneBit(int i) {
// HD, Figure 3-1
i |= (i >> 1);
i |= (i >> 2);
i |= (i >> 4);
i |= (i >> 8);
i |= (i >> 16);
return i - (i >>> 1);
}

最佳答案

来自源码顶部的注释...

   40    * <p>Implementation note: The implementations of the "bit twiddling"
41 * methods (such as {@link #highestOneBit(int) highestOneBit} and
42 * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
43 * based on material from Henry S. Warren, Jr.'s <i>Hacker's
44 * Delight</i>, (Addison Wesley, 2002).
45 *

Hacker's Delight亨利·沃伦 (Henry S. Warren)。

关于java - Java 类 Integer 和 Long 的源代码中的 "HD"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15057710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com