473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Reverse AND operation

vpawizard
Hello,
I have two numbers x and y. x & y are ANDed together to produce z. I know the values of z and y. Is there any way to retrieve the value of x?
Jan 3 '07 #1
4 2300
Just think about it:

if y == 0 and z==0, x could be anything; therefore there is no reverse and operation.

In general:

if y == 0, then z== 0, and x could be anything
if y == 1 and z == 0, x = 0
if y == 1 and z == 1, x = 1

use xor for a reversable operation.
Jan 4 '07 #2
Well I am aware of the XOR operation. However, the case is some operation is returning me the ANDed value and I have to extract the first operand and all I know is the result of ANDing and the second operand for AND.
Jan 4 '07 #3
DeMan
1,806 1GB
If you do come up with an answer, however, please post, as prime numbers show some interesting behaviour in logic arithmetic, so being able to undo logical operations could be a really powerful thing to do.....
Jan 4 '07 #4
Unfortunately, that is impossible in the general case. If any bit of y is 0, then you cannot reverse the operation. And if all bits of y are 1, then x & y == x, so an algorythm that finds the inverse of the bitwise (or logical) and operation is basically useless.
Jan 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
6
by: Zri Man | last post by:
I'm relatively new to DB2 and was reasonably amused to see the REVERSE SCAN availability for Indexes. My assumptions are as follows: DB2/UDB uses B-Tree for indexing by default and is likely...
24
by: Sathyaish | last post by:
This one question is asked modally in most Microsoft interviews. I started to contemplate various implementations for it. This was what I got. #include <stdio.h> #include <stdlib.h> #include...
4
by: Alessandro Riolo | last post by:
I've got a weird thing when reverse engineering a c# project which is declaring and then using an event of type CancelEventHandler as in the following snippet: ... public event...
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
4
by: ranjanmg1 | last post by:
I have a unsigned char.. i need to reverse it.. what the easiest way to do it?? i dont want to tap each bit save and restore etc etc.... Is it possible to perform some bitwise operation which...
15
by: rajash | last post by:
Thanks for the additional comments. Here is a solution to an exercise I had problems with. I still don't think it's really what's wanted as it uses a "state variable" n - but I can't see how to...
9
by: Mark Bryan Yu | last post by:
This set of codes works: But this doesn't: None Please explain this behavior. range(5) returns a list from 0 to 4 and reverse just reverses the items on the list that is returned by
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.