I try to do as much using bitwise operators as possible in this library. So far the best option I have found is this: https://gist.github.com/wvanbergen/8899809. Maybe you can think of a nicer way?