Author: Heiner Marxen
Date: 13:43:38 04/29/00
Go up one level in this thread
On April 29, 2000 at 16:05:59, KarinsDad wrote: >Most every programmer knows the simple b & -b to calculate least significant >bit. However, us run of the mill programmers do not know of a simple way to >calculate most significant bit. > >Is there such a beast? > >KarinsDad :) I do not know about any simple trick like that for LSB. The 256-byte table approach works here also (you need a different table, of course). I have somewhere picked up a completely different idea (do not remember where), but have never tried to code anything for it: you may try to use the floating point unit's capability of normalizing denormalized floating point numbers. A normalized FP number has an (implicit) 1 as MSB of the mantissa. Just above zero IEEE FP format defines denormalized numbers, which do not have the implicit MSB = 1. You can stuff up to 52 (?) bits into the mantissa of a denormalized FP number, multiply by a power of two, say 2^64, to force a normalized number and then extract the FP-exponent. That way you can get the position of the MSB. I have no idea, how efficient that method is. It is also not completely portable, but IEEE is quite standard. Heiner
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.