java - BitSet 向后显示值?

标签 java bitset

我已经设置了以下使用 Java 运行的代码:

BitSet bitSet = BitSet.valueOf(new byte[] { (byte)15 });
System.out.println(bitSet);

出乎我的意料

{0, 1, 2, 3} //the indexes of the 1's in the bitset

代替

{ 4, 5, 6, 7 }.

15 的 2 的补码写成 00001111(占 1 个字节),如果我没记错的话。

这让我想知道为什么 BitSet 会向后显示索引。有什么合理的解释吗?

最佳答案

引用 BitSet 的 Java 标准:

Returns a string representation of this bit set. For every index for which this BitSet contains a bit in the set state, the decimal representation of that index is included in the result. Such indices are listed in order from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.

如上所示,顺序是“从低到高”。这意味着首先是最低有效位(个位),最后是最高有效位。

排序(符号顺序从左到右或数字顺序从最少到最多)都有意义,尽管方式不同。

关于java - BitSet 向后显示值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11166056/

相关文章:

java - 根据模型值隐藏 JTable 中的单个单元格

c# - 无法以与 C# 相同的格式为 WCF 服务传递 java 参数

Java直接引用哈希值

java - java中BitSet的nextClearBit()实际上是如何工作的?

c++ - 是否可以创建一个位集 vector ?

java - 我可以在 Java 属性文件中的多行属性之间或之后放置注释吗?

java - Couchbase - 自动生成带有用户定义后缀的 key

允许轻松连接 BitSet 的 Java BitSet

algorithm - 所有子数组的异或之和

c - 如何在 C 中实现位集?