0
a|b=c

knowing a and c, how to calculate b

For example:

0011 | b = 0111

Knowing a = 0011 and c = 0111, how to figure out b to be 0101

Gaurav Sehgal
  • 7,422
  • 2
  • 18
  • 34
xxking
  • 77
  • 10
  • 2
    Your problem is under-determined. It can exist several values... The most trivial answer is if a|b=c for b unknown then b=c is a valid answer... – Jean-Baptiste Yunès May 04 '18 at 08:15
  • could you please clarify your question. – Mike May 04 '18 at 08:16
  • You are confusing or `|` and xor `^`, or is under-determined. However, with xor the solution would be [What is inverse function to XOR?](https://stackoverflow.com/questions/14279866/what-is-inverse-function-to-xor) – Lanting May 04 '18 at 08:29

2 Answers2

0

There will be more than one correct answer.

For simplicity consider the trivial example: 1|0 = 1 i.e. a=1, b=0 and c=1. In this case, b can also be 1.

So given that the bit in a is 1, we won't be able to know for sure whether the bit in b is 0 or 1.

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0

In some logics there is also a "value" for unknown X

So if you want to get bfrom a|b=c => 0011 | b = 0111 the in my mind nicest answer would be 01XX

Everything that is:

  • 0 in c has to be 0 in b
  • 1 in c and 0 in a has to be 1 in b
  • 1 in c and 1 in a is unknown X
Kami Kaze
  • 2,069
  • 15
  • 27