Talk:Find first and last set bit of a long integer: Difference between revisions

Content added Content deleted
Line 33: Line 33:


[[User:NevilleDNZ|NevilleDNZ]] 02:02, 8 December 2011 (UTC)
[[User:NevilleDNZ|NevilleDNZ]] 02:02, 8 December 2011 (UTC)

== Initial C code specimen requires a long int algorithm ==

The use of #define in the C code specimen works really well when unrolling a loop.

The code issues are:
* code specimen lacks any more generally algorithm that would work - for example - with 128, or 256 width '''bits'''.
* the code confuses "lowest set bit" (a bit order concept) with "least significant bit" (an integer concept). These are actually almost opposites on most machines.
* ditto for "upper set bit" and "most significant bit".
* the results are in hex eg. 0xc0ffee, not binary 0b110000001111111111101110 making it difficult to visually discover/confirm the results.

Try using [[wp:Duff's device|Duff's device]] to unroll wider '''bits''' types.

NJoy [[User:NevilleDNZ|NevilleDNZ]] 02:39, 8 December 2011 (UTC)