Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string to byte array problem

 
Ravindra Harige
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I've long sequence of 0 and 1's in a string and i want this string to be stored in a byte array,but the size of byte array should be
( [number of 0's and 1's in string]/8 )
for example,if i've 80 consecutive 0's and 1's in a string then i want a byte array of size 10 consisting of the exact sequence of 0's and 1's as in string.
please help me on how to go about this..


regards
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all you must decide what to do if the length is not a multiple of 8. Do you add zeros at the start? At the end? Something else?

But lets suppose you've solved that, and the string is now in the right format. You can use something similar to this:

[ March 24, 2008: Message edited by: Rob Prime ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic