ensure k is power of 2 to match java