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

In summary, you can't compute B from A using the code you provided, and you might not be able to find an inverse OR operator that will work.
  • #1
Medicol
223
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
  • #2
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..
 
  • #3
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
  • #4
My problem was something like this
A<<=5;
B=(A|=0x80);

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

:D Have a good day!
 
  • #5


Based on the given code, it seems that the inverse OR operator being sought is the AND operator. This is because the code is using the OR operator to add a value (0xFF) to A only when the boolean b is false. Therefore, to compute B from A, the inverse operation would be to remove the added value (0xFF) from A using the AND operator.

The code could be rewritten as:
B = A >> 5
if NOT b then
B = B AND (NOT 0xFF)

This would result in B being computed from A, with the added value being removed if b is false. However, it is worth noting that this code may not be the most efficient or clear way to compute B from A, and it may be beneficial to consider alternative methods.
 

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

1. How does the OR operator work in finding a value?

The OR operator, represented by the symbol "||" in most programming languages, is a logical operator that returns a boolean value of true if at least one of the conditions being evaluated is true. If both conditions are false, then the OR operator will return a boolean value of false.

2. Can the OR operator be used to find a specific value in a dataset?

No, the OR operator is primarily used for evaluating boolean expressions and does not have a specific function for finding values in a dataset. It can be used in combination with other operators, such as the equality operator (==), to search for values that meet specific conditions.

3. How can I use the OR operator to find multiple values at once?

The OR operator can be used to find multiple values by using it in combination with the equality operator (==) or other logical operators. For example, if you want to find all values that are either equal to 5 or greater than 10, you can use the expression "value == 5 || value > 10".

4. What is the difference between the OR operator and the AND operator?

The OR operator returns true if at least one of the conditions being evaluated is true, while the AND operator returns true only if both conditions are true. In other words, the OR operator is inclusive, while the AND operator is exclusive.

5. Can I use the OR operator to combine more than two conditions?

Yes, the OR operator can be used to combine any number of conditions. For example, if you want to find all values that are either equal to 5, greater than 10, or less than 0, you can use the expression "value == 5 || value > 10 || value < 0".

Similar threads

  • Programming and Computer Science
Replies
3
Views
793
  • Programming and Computer Science
Replies
4
Views
404
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
Back
Top