how to Reverse bitwise & operator

Hi,

I'm new to bitwise operations.
Please help me to do this:

1
2
3
var str = "some string"
for each characters in str:
     past char & this char

this is ok, & i can do this. but, now i want to decode this to find original string. how can i do this? any idea?

thanks for your help.
I don't think it's possible for AND, since it destroys information.
For example, x&0==0. Now there's no way to know what the value of x was, because it was completely overwritten with zeroes.
dear Helios,

I have written this algorithm on the paper.
can you convert to c++ source code?

s(n) means the n'th character in original variable.
e(n) means the n'th character in encode variable.
note that binaries are the ASCII characters.


original variable:
10011101 -> s(1)
10001011 -> s(2)
01010101 -> s(3)
11110100 -> s(4)

encoded variable:
10011101 -> e(1) = s(1)
11101001 -> e(2) = s(2) & s(1)
00100001 -> e(3) = s(3) & s(2)
01011110 -> e(4) = s(4) & s(3)
e(n) = s(n) & s(n-1)

decoded variable (same as original string variable)
10011101 -> s(1) = e(1)
10001011 -> s(2) = e(2) & s(1)
01010101 -> s(3) = e(3) & s(2)
11110100 -> s(4) = e(4) & s(3)
s(n) = e(n) & s(n-1)



On the paper it is OK & without any problem, but I can't convert this to c++ source code.
Can you do this?

And... I'm wondering is it possible to do this with OR operator? for my work, this operator is better than AND.

thanks.
Last edited on
Uh... That's not a bitwise AND. 10011101 & 10001011 doesn't give 11101001. It gives 10001001.
That looks more like a bitwise XNOR. Furthermore, if that was bitwise AND, the operation couldn't be reversed with that algorithm.
Ohh... sorry!!

can you solve my problem by xnor?

thanks.
The key to this problem is doing things in the correct order.
original v:
v[0]
v[1]
v[2]
v[3]

v after encoding:
v[0]
v[0]^~v[1]
v[0]^~v[1]^~v[2]
v[0]^~v[1]^~v[2]^~v[3]

Result of applying
1
2
3
for (i=1;i<n;i++){
    v[i]^=~v[i-1];
}

for decoding:
v[0]
v[1]
v[0]^~v[2]
v[1]^~v[3]

I think you should have enough to figure it out.
Topic archived. No new replies allowed.