• Post Reply Bookmark Topic Watch Topic
  • New Topic

Working on bits in java  RSS feed

 
Abhishek Yadav
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am working on a project in which i have to create a data structure of of bits(say 232 bits of data, 29 bytes). In this 232 bits, 0 to 2 bits represent something,3 to 6 bits represents something,......229 to 231 bits represent something. This data of 232 bits is used and is encripted. Can anybody please suggest how to implement it. If this can not be implemented in java, any alternatives.

Thanks & Regards
Abhishek Yadav
SCJP, SCBCD
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the API for class names starting with "Bit"?
 
Abhishek Yadav
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, in the API there is a class java.util.BitSet, this object can be used as a container for 232-number of bits, and each bit value can be set to
1(true) or 0(false), but i can not get the 232 bit data from this bit set.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, as a BigInteger.

First convert the BitSet to a String:

Vice versa is a lot simpler:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!