Find value from OR operator

  • Thread starter Medicol
  • Start date
  • #1
223
53

Main Question or Discussion Point

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..
 

Answers and Replies

  • #2
33,274
4,983
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..
 
  • #3
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.
 
  • #4
223
53
My problem was something like this
A<<=5;
B=(A|=0x80);

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

:D Have a good day!
 
Top