This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes use of bitset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "use of bitset" Watch "use of bitset" New topic
Author

use of bitset

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,

May I kow the use of a bitset?

I find it difficult to understand what is bitset even after going through the API

Thanks in Advance.



Rakesh Kadulkar
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It represents binary bits (if you don't know what a bit is, check this). For example, imagine that you have the following byte : 00001100 (=12 in decimal). You can represent it like this :

The ouput is {2, 3}, which tells you that bits 2 and 3 are on.

Imagine that you have another byte 00001000, and you want to "and" its value with the first byte. The BitSet class allows you to do the basic logical functions "and", "or", "xor".

The output is now {3}, because bit 2 was turned off during the "and" operation.

(I don't remember having used this class ever before)

[My Blog]
All roads lead to JavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Bits are obviously numbered from right to left, starting at 0, so the least significant bit in that example is no 0 and the most significant bit is no 7.
 
GeeCON Prague 2014
 
subject: use of bitset