Question: I have a problem with ionic framework's native scroll. The following works fine in the browser, but not when compiled to iOS. If I poll the `$ionicScrollDelegate.getScrollPosition()` at an interval, I don't get up-to-date values for positions. It's only if the deceleration ends or the user touches again that the value is updated. I spelunked through all the ionic scroll code, but it seems that the `__scrollLeft` value comes from an even deeper internal API since I'm trying to use native, not js scrolling. 

In an attempt to hack around it, I tried using the DOM API to get the window-relative position of my content:

`inversePosition = divContainer.getBoundingClientRect().left;`

but this suffered from the same lack of updates. This makes me think it may not even be possible. 

Is there a way to get the position more directly? I'm willing to dive into the ionic js bundle myself, but I don't know where to start in terms of even finding the core cordova scrolling API documentation. 

Basically, my use-case is similar to that of a mapping app, I need realtime accurate scroll position data. 

I opened an [issue](https://github.com/driftyco/ionic/issues/6506) in the ionic lib, but I doubt anyone will get to it with 398 other open issues....

tagging phonegap because because phonegap wraps cordova as well, and solutions in phonegap may be applicable to this problem.

Answer: 
You can convert the strings to binary using the built-in [int() function](https://docs.python.org/2/library/functions.html#int) and passing 2 as the base:

```
a = int('010110', 2)
b = int('100000', 2)

```

then OR the two values and count the bits by converting to a string and counting the "1" characters:

```
print bin(a | b).count("1")

```
You could write a custom class derived from `str` and override its magic method responsible for the binary OR operator `|`.

There are many ways to implement the OR. The probably easiest one was already described by [@samgak](https://stackoverflow.com/users/696391/samgak) in his answer, you can use `int` with specifying the base number as 2 and then use its `|` operator:

```
class bitstr(str)
    def __or__(self, other):
        return bin(int(self, 2) | int(other, 2))[2:]
        # need to slice because 'bin' prefixes the result string with "0b".

```

This is how you could use it:

```
a = '010110'
b = bitstr('100000')

print(bitstr(a) | b)
# Output: 110110

```

You see that you need a conversion to `bitstr` somewhere, but it does not matter at which point. Also, for all other operations except the `|` operator, our custom `bitstr` behaves exactly like a normal `str` string, so you could use that everywhere if you want.

[See this code running on ideone.com](http://ideone.com/eYrYCO)