srlabib's blog

By srlabib, 4 years ago, In English

Hi All ! Recently I and turzo_sawroop have done some observations on bitwise operations and found these equations and properties that you may find helpful. I want to share them with you in a nutshell. Here is a shortlist of them:

Some properties of bitwise operations:

  • a|b = a⊕b + a&b
  • a⊕(a&b) = (a|b)⊕b
  • b⊕(a&b) = (a|b)⊕a
  • (a&b)⊕(a|b) = a⊕b

Addition:

  • a+b = a|b + a&b
  • a+b = a⊕b + 2(a&b)

Subtraction:

  • a-b = (a⊕(a&b))-((a|b)⊕a)
  • a-b = ((a|b)⊕b)-((a|b)⊕a)
  • a-b = (a⊕(a&b))-(b⊕(a&b))
  • a-b = ((a|b)⊕b)-(b⊕(a&b))

Hope you like it. Please let me know if you find any issues. All of these properties are elaborated in this blog here. You can also check it out to learn more!

  • Vote: I like it
  • +50
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Third equation is deductible from the second if you apply $$$\oplus a\oplus b$$$ to both sides

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

it is helpful

»
19 months ago, # |
  Vote: I like it +3 Vote: I do not like it

This is helpful for solving this problem, https://codeforces.me/problemset/problem/1556/D Thank you srlabib and turzo_sawroop!!

»
22 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

thanks bro solved C in today's contest using one equation from here

  • »
    »
    21 hour(s) ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    which one did you use?

    • »
      »
      »
      21 hour(s) ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      a + b = a ^ b + 2 (a & b)

    • »
      »
      »
      21 hour(s) ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      the 2nd addition eqn . Making a&b == 0 .

      • »
        »
        »
        »
        11 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        if a = x + k and b = y + k what is the approach now , how do i find k?

        • »
          »
          »
          »
          »
          11 hours ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          Just make the maximum of x+k and y+k equal to $$$2^n>10^9$$$. This will make the smaller one of the two less than $$$2^n$$$, making the '&' operation's result be 0.

»
22 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

very useful