string to bitmask

  • Thread starter Thread starter Just D
  • Start date Start date
J

Just D

All,

What's the easiest way to convert the string like 1001010101101010101 into a
binary mask of type Int64 and back? ConvertBitmask or something like that?

Just D.
 
I would probably just write a loop.

char [] chars = string.ToCharArray[]
for(int i=0;i<chars.Length;i++) {
yourvalue |= (chars - '0') << i;
}

or with unsafe code
int length = string.Length;
fixed(char *start = string) {
while(current < length) {
yourvalue |= (chars - '0') << current;
current++;
}
}

You could also use the BitVector32 class if you prefer to not deal with
shifting etc.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top