aspose file tools*
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: 14687
    
  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: 38858
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of bitset