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
AI Thread 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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top