How Can I Compute Variable B from Variable A Using Inverse OR Operator?

  • Thread starter Thread starter Medicol
  • Start date Start date
  • Tags Tags
    Operator Value
Click For Summary
The discussion centers on the challenge of reversing a computation involving two variables, A and B, where A is derived from B through a left shift operation and a conditional bitwise OR operation. The user seeks to determine how to compute B from A, given a boolean condition. The primary confusion arises from the non-injective nature of the mapping from B to A, particularly when the boolean condition is false, leading to multiple potential B values mapping to the same A value. This ambiguity complicates the reversal process, as there is no unique way to retrieve B from A without additional information. The discussion highlights the importance of understanding the types of A and B and the implications of bitwise operations in this context.
Medicol
Messages
223
Reaction score
54
I have 2 variables A and B.
A can be computed from B like this
Code:
Input: BOOL b, OBJECT B
A=(B<<5)
if NOT b then 
   A=[A OR 0xFF]
Now I would like to compute B from the above code
Code:
Input: BOOL b, OBJECT A
It can be either
Code:
B=A>>5
if NOT b then
   B= ?
or
Code:
if NOT b then
   B=?
B=A>>5
I am not sure which way as well as the correct inverse OR operator it is that I'm seeking, I'm so confused..
 
Technology news on Phys.org
Medicol said:
I have 2 variables A and B.
A can be computed from B like this
Code:
Input: BOOL b, OBJECT B
A=(B<<5)
if NOT b then
   A=[A OR 0xFF]
It's not clear from your explanation what you're trying to do here. Also, because you haven't indicated what type A is or what the underlying type is for B (i.e., the number of bits), it's hard for me to determine what the code above will produce.

All I can say for sure is that the low 8 bits of A will be set to 0xFF.
Medicol said:
Now I would like to compute B from the above code
Code:
Input: BOOL b, OBJECT A
It can be either
Code:
B=A>>5
if NOT b then
   B= ?
or
Code:
if NOT b then
   B=?
B=A>>5
I am not sure which way as well as the correct inverse OR operator it is that I'm seeking, I'm so confused..
 
Medicol said:
Now I would like to compute B from the above code
You can't, assuming that your OBJECTs are integer-like objects and your OR is a bit-wise or. The problem is that your function that maps B values to A values is not a one to one, onto mapping. One problem occurs with the computation when b is false. Any value between of 0 and 7 maps to 255, and value between 8 and 15 maps to 511, and so on. So which of the eight possible values to you want 255 to map to?

Another problem: What if A is 1? There is no (b,B) pair that produces a value of 1.
 
  • Like
Likes Medicol
My problem was something like this
A<<=5;
B=(A|=0x80);

then
B&=0x7F;
A=(B=>>5);

:D Have a good day!
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
Replies
4
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
Replies
15
Views
3K
Replies
2
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K