http://www.perlmonks.org?node_id=801728


in reply to Re^2: Decimal to Hexadecimal conversion and extraction MSB
in thread Decimal to Hexadecimal conversion and extraction MSB

I concur that the OP seems to be asking something different from what I answered. But the leftmost bit of a non-negative integer of any length is one unless the integer is zero. So I don't think that is what was intended.

The OP could also have been asking for the position of the leftmost "1" bit. If the integer is not zero, this is the integer portion of the quotient "log(number) / log(2)" (for a non-zero base log).

I read the tea leaves and inferred that the OP wanted to work with integers of a fixed size. (The part of the question that asked about bit shifting gave me a strong push in this direction. That is surely a prejudice based on my experience.)

  • Comment on Re^3: Decimal to Hexadecimal conversion and extraction MSB