• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Binary Data Creation

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to create a binary data like this:

The data: 1, 2, 3, 4, 5, 6, 7, 8, 9

It should be represented as one record in a binary file, this record should be 8 bytes long (64 bits). What makes it difficult is that each digit in that data should be represented as 5-bit. Example, 1 should be 00001. Therefore, this record would be:

[append 000s here to make 64 bits]000010001000011..[till 01001]

My problem is, how could I create a binary data, adding each one individually, like bit by bit manipulation. The byte is already 8 bits. How can I add one data as 5 bits...

like, insert 1, then insert 2.. but still fixing it to 64 bits. I am trying to do bit shift operations, but I still couldn't end up with 5 bits as 1 byte. I also tried BitSet but not successful.

I hope you get the idea. Thanks in advance!
 
Maruthi Janardhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you go:



It will put numbers from 1 through 9 as 5 bit representations into a long. Since long is 64bits in size, it finally carries the binary pattern you need
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!