tags:

views:

64

answers:

3

suppose we have two numbers i want write program which print common bits subsequent which occurs in these number or

 1000010111001010100011110001010010101001011101001001001
0101 01110011011001010111101111111010001001011

one of the answer should be 0101 but constraint is that we should make bitwise operations and mathematical operations and not string problems ( longest common subsequent) thanks

A: 

Assuming you have two 32 bit ints a and b. Shift the bits in b by i, and wrap them around (so that the bit that falls out on the right will come in on the left) and xor it with a. Let i go from 0 to 31. This will give you 32 results. If my reasoning is correct, the result with the longest common subsequence should be the one with the most 0s (counting the 0s can be done in a loop for instance). If not, this should at least be a good starting point.

inflagranti
please how me a few example i did not understand well
@davit-datuashvili, instead of continuing to ask for spoon-feed answers, I suggest you react to the comments to your question for once. But I get the impression you are immune to them: I have never seen you answer any request for clarification.
Bart Kiers
A: 

Take a look at the Sequitur-Algorithm.

tur1ng
A: 
common_ones = a & b;
common_zeros = ~a & ~b;
common_sequences = common_ones | common_zeros;

for example:

a 1000010111001010100011110001010010101001011101001001001
b 0000000000010101110011011001010111101111111010001001011
c 0111101000100000101111010111111010111001011000111111101

to clear the single bit sequences you can use this:

c = c & ( c >> 1 );
c = c | ( c << 1 );

c 0111100000000000001111000111111000111000011000111111100

It is not clear if this is what you want, but this is a quick and easy way to find all common bit sequences at the same position in two values. If you are looking for common bit sequences at any position, you would need to rotate one value into each bit position and perform the above tests.

drawnonward
alternatively common_seqence = ~(a^b)
jk