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

Discussion Overview

The discussion revolves around the computation of variable B from variable A using a bitwise operation, specifically focusing on the inverse of the OR operator. Participants explore the implications of the operations defined in the context of programming and bit manipulation, with a particular emphasis on the conditions under which these computations can be performed.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a method to compute A from B using a left shift and a conditional OR operation, expressing confusion about how to reverse this process to compute B from A.
  • Another participant notes the lack of clarity regarding the types of A and B, suggesting that the underlying bit representation is crucial for understanding the output of the operations.
  • A third participant argues that it is not possible to compute B from A due to the non-injective nature of the mapping, highlighting that multiple values of B can lead to the same value of A, particularly when b is false.
  • A later post introduces a different approach to the computation involving bitwise operations but does not clarify how it relates to the original problem.

Areas of Agreement / Disagreement

Participants express differing views on the feasibility of computing B from A, with some asserting that it cannot be done due to the nature of the mapping, while others are uncertain and seek clarification on the operations involved. No consensus is reached on the correct approach or the inverse operation needed.

Contextual Notes

Participants highlight limitations in the discussion, including the unspecified types of A and B, the ambiguity of the inverse OR operation, and the implications of the conditional statements on the mapping between A and B.

Medicol
Messages
226
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   Reactions: Medicol
My problem was something like this
A<<=5;
B=(A|=0x80);

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

:D Have a good day!
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
Replies
4
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · 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 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K