0

I have the following statement:

set_bit = bin(int('1',2) | (int('1',2))).count('1')

This is how I broke it down:

  • int('1',2): Convert the string '1' into int using base 2, so it'll be 1.
  • count('1'): Basically count all instances where there is a one in the expression
  • I understand that bin converts the int value into binary

My issue is what int('1',2) | (int('1',2) means.

Adib
  • 1,282
  • 1
  • 16
  • 32
  • 1
    I'm confused what this is trying to accomplish. `1 | 1` is `1`, then `count('1')` would again return `1`? – OneCricketeer Oct 03 '16 at 21:32
  • @cricket_007 it was in a hackerrank question, and the solution showed this method. But now that you mention that it is a bit 'or' statement, I do agree that it's redundant. – Adib Oct 03 '16 at 21:33

0 Answers0