Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Find value from OR operator

  1. Jan 14, 2015 #1
    I have 2 variables A and B.
    A can be computed from B like this
    Code (Text):
    Input: BOOL b, OBJECT B
    if NOT b then
       A=[A OR 0xFF]
    Now I would like to compute B from the above code
    Code (Text):
    Input: BOOL b, OBJECT A
    It can be either
    Code (Text):
    if NOT b then
       B= ?
    Code (Text):

    if NOT b then
    I am not sure which way as well as the correct inverse OR operator it is that I'm seeking, I'm so confused..
  2. jcsd
  3. Jan 14, 2015 #2


    Staff: Mentor

    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.
  4. Jan 20, 2015 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  5. Jan 20, 2015 #4
    My problem was something like this


    :D Have a good day!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook