Bit Scan Forward and Reverse

Matimus mccredie at gmail.com
Fri Jan 18 16:12:49 EST 2008


On Jan 18, 12:01 pm, Thomas Dybdahl Ahle <lob... at gmail.com> wrote:
> Hi, I'm writing an app in python, and I'm storing some a lot of data in
> bitmaps.
> I need a way to find the first or latest set bit in a 64bit number, and
> for that I've implemented a small routine.
>
> Thing is that this routine is not as fast as I'd wish. I know most
> processors implement BSF and BSR calls to do this efficiently.
> Is there anyway to access those calls from python?
>
> I'd still have my routine as a fallback on nonsupporting architectures.
>
> --
> Med venlig hilsen,
> Best regards,
> Thomas

There isn't a simple way, but you have a couple of options:

1. put the code in a dll and call it from ctypes.
2. see extending and embedding in the documentation.

Matt



More information about the Python-list mailing list