当前位置: 首页 > 面试题库 >

Java BitSet示例

孔鹤龄
2023-03-14
问题内容

我正在寻找一个BitSet适用于0和1的Java
示例。我尝试查看Javadocs,但仅阅读该书就无法理解该类的用法。例如,会怎么andor以及xor在两个不同的方式工作BitSet的对象?

例如:

  BitSet bits1 = new BitSet();
  BitSet bits2 = new BitSet();

  bits2.set(1000001);
  bits1.set(1111111);

  bits2.and(bits1);

  System.out.println(bits2);

如果我这样做,它返回bits2为空,那是为什么?


问题答案:

对于您提到的特定问题:调用时bits2.set(1000001),请将百万分之一和第一位设置为true。然后,当与相交时bits1,它们分别设置了100万,11.1万和111st位,它们没有共同的位。

我想你的 意思

 bits2.set(0); // set the 0th bit
 bits2.set(6); // set the 6th bit

这有助于清除一切吗?



 类似资料:
  • Composite Images watermark(['/img/shepherd.jpg', '/img/logo.png']) .image(watermark.image.lowerRight()) .then(function (img) { document.getElementById('composite-image').appendChild(img); }); Al

  • 示例的Python源代码或者交互界面都可以使用标准reST模块实现.在正常段落后面跟着 :: 开始,再加上适当缩进. 交互界面需包含提示及Python代码的输出. 交互界面没有特别的标记. 在最后一行输入或输出之后,不应出现空的提示; 这是一个什么都不做的例子: >>> 1 + 1 2 >>> 语法高亮显示由 Pygments (如果安装) 优雅的显示: 每个源文件都有高亮语言”highlight

  • Redux 源码 中同时包含了一些示例。这些示例中的大多数也在CodeSandbox上,这是一个在线编辑器,可让您在线测试示例。 原生版 Counter 运行 Counter Vanilla 示例: git clone https://github.com/reactjs/redux.git cd redux/examples/counter-vanilla open index.html 该示

  • 这是一些 Mithril 的示例: Animation DBMonster Markdown Editor SVG: Clock, Ring, Tiger ThreadItJS TodoMVC

  • 已经有超过50,000本图书使用GitBook.com发布。 文档 DuckDuckHack 文档 by DuckDuckGo Loomio Handbook and guide to using Loomio both by Loomio Enspiral Handbook by Enspiral Webmagic开发文档 by https://github.com/code4craft/web

  • 这里列出了所有示例: adc_vol_sample.c dynmem_sample.c event_sample.c httpclient_sample.c hwtimer_sample.c i2c_aht10_sample.c idlehook_sample.c interrupt_sample.c iwdg_sample.c led_blink_sample.c mailbox_sample.

  • 下面的例子说明了部署描述文件模式中列出的定义的用法。 一个简单的例子 CODE EXAMPLE 14-1 Basic Deployment Descriptor Example <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://

  • 计算变量 首先,让我们从一些必要的代码开始。 这个例子的目的是如果条件满足,将 a 和 b 计算后的值绑定到 c 上。 下面就是必要的代码示例: // this is standard imperative code var c: String var a = 1 // this will only assign the value `1` to `a` once var b = 2