integer to binary bits

  • Thread starter Thread starter Muhs
  • Start date Start date
M

Muhs

Hi all!!

Im working with mutation testing...

i have a file which consist of data like this
10110011
10110111
01010001

i read the file and store it in an integer array... now i want to use
the integer as seperate bits like the first one as, 1,0,1,1,0,0,1,1.
This is because i wnat to find the hamming distance between the two
integers. Can any one of you tell me how to do it...
 
Muhs said:
Im working with mutation testing...

i have a file which consist of data like this
10110011
10110111
01010001

i read the file and store it in an integer array... now i want to use
the integer as seperate bits like the first one as, 1,0,1,1,0,0,1,1.
This is because i wnat to find the hamming distance between the two
integers. Can any one of you tell me how to do it...

The easiest way to do this is to use the BitArray class. However, you
can also do it with bit manipulation - shifting (<< and >>) and bitwise
anding (&).
 
Muhs said:
Hi all!!

Im working with mutation testing...

i have a file which consist of data like this
10110011
10110111
01010001

i read the file and store it in an integer array... now i want to use
the integer as seperate bits like the first one as, 1,0,1,1,0,0,1,1.
This is because i wnat to find the hamming distance between the two
integers. Can any one of you tell me how to do it...

You may like the BitArray class, as in

BitArray ba = new BitArray(new int[] { 0xB3 });

or else just calculate the hamming distance directly:

int one, two;
int differences = one ^ two;

byte hdistance = 0;
while (differences != 0)
{
hdistance++;
differences = differences & (differences - 1);
}
 
Bitwise anding gives either true or false i want numbers...

If you could just elaborate it a bit more that would be truly
helpful..
 
Muhs said:
Bitwise anding gives either true or false i want numbers...

No, bitwise anding of integers gives integers:

using System;
class Test
{
static void Main()
{
int value = 132;

Console.WriteLine((value & (1 << 0)) >> 0);
Console.WriteLine((value & (1 << 1)) >> 1);
Console.WriteLine((value & (1 << 2)) >> 2);
Console.WriteLine((value & (1 << 3)) >> 3);
Console.WriteLine((value & (1 << 4)) >> 4);
Console.WriteLine((value & (1 << 5)) >> 5);
Console.WriteLine((value & (1 << 6)) >> 6);
Console.WriteLine((value & (1 << 7)) >> 7);
}
}

That displays the bits of the number 132 from least significant to most
significant. (I haven't put it in a loop because I think that might
confuse things a bit.)
 
Thanks for the reply... I'll try to do it this way... Hopefully it
works the way i want it to work.
 
Hi all!!

Im working with mutation testing...

i have a file which consist of data like this
10110011
10110111
01010001

i read the file and store it in an integer array... now i want to use
the integer as seperate bits like the first one as, 1,0,1,1,0,0,1,1.
This is because i wnat to find the hamming distance between the two
integers. Can any one of you tell me how to do it...

Havent a clue to what you are asking... but its a bit late...

checked out http://www.vldb.org/conf/2002/S10P02.pdf and it got me
more confused...
all data in a normal computer is binary and can be treated as such,

so as jon said u can always in a integer anyway check if a bit is 1 or
not by and...

but hamming distance... mutation testing... difference between two
integers.. thats "-"

Got some pseudo code out of thet article and I dont catch a thing...

initialise c[1; 1] : : : c[m; log n] = 0
for all tuples (i; dk) do
for j = 1 to m do
c[j; hashj(i)] = c[j; hashj(i)] + dk
for j = 1 to m do
for k = log n downto 1 do
if c[j; k] = 0 then
minzero = k
total = total + minzero
return(1:2928  2total=m)

well, go look it up in the pdf.. if you dont trust me...

//CY
 
Back
Top