On Saturday, August 13, 2016 at 9:22:14 AM UTC-4, jw3126 wrote:
>
> 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
>

Normally to compute this function you would just check whether the 
bitwise-and with 10000000 is nonzero.  e.g.

firstbit(n::Union{UInt8,Int8}) = (n & 0x80) != 0
firstbit(n::Union{UInt16,Int16}) = (n & 0x8000) != 0
firstbit(n::Union{UInt32,Int32}) = (n & 0x80000000) != 0
firstbit(n::Union{UInt64,Int64}) = (n & 0x8000000000000000) != 0
firstbit(n::Union{UInt128,Int128}) = (n & 
0x80000000000000000000000000000000) != 0
firstbit(n::Integer) = leading_ones(n) > 0

Reply via email to