Sorry my question was confusing. What I want is a function that behaves as 
follows on bittypes:

*0*0101101 -> 0
*0*1110101 -> 0
*0*1011011 -> 0
*1*0011101 -> 1
*1*1010001 -> 1
*1*0110111 -> 1

function firstbit(x) 
    leading_ones(x) > 0
end

has the right behaviour, but it feels indirect and I wonder if there is a 
more performant way.




On Saturday, August 13, 2016 at 3:05:31 PM UTC+2, Scott Jones wrote:
>
> Do you want the least significant 1 bit set?  Then use trailing_zeros(x). 
> (I use that a lot for packing floating point values, which are right 
> justified in the word (if you consider the msb as being the rightmost bit).
> If you want the most significant 1 bit set, then leading_zeros(x) (which 
> other people have already mentioned).
>
> On Thursday, August 11, 2016 at 7:48:08 PM UTC+2, jw3126 wrote:
>>
>> I have a bitstype and want to know the number of ones in its bit 
>> representation as well as the first bit. How to accomplish these in a 
>> performant way?
>>
>

Reply via email to