Sorry! I should have been more specific. What I want is: 0 -> 0 1 -> 1 0x8 -> 4 0x1f -> 5 13 -> 5
i.e. number of bits needed to represent the number. I want to pack 2 or 3 values into a unsigned int, (maybe a UInt16, up to a UInt128), that I can then use for sorting purposes efficiently. (much more cache efficient, eliminates a bunch of pointer references, etc.) Any idea how? (normally, I'd just use the assembly instructions available that do this, but I want to do this in pure Julia [it would be nice if the Julia code could actually be smart enough to generate the correct native code ;-) ) Thanks! On Tuesday, October 6, 2015 at 11:03:03 AM UTC-4, Steven G. Johnson wrote: > > > > On Tuesday, October 6, 2015 at 10:59:04 AM UTC-4, Scott Jones wrote: >> >> I couldn't find anything yet - is there a recommended / fastest way to >> get the number of bits in a number (I really only need it for unsigned >> values). >> Thanks >> > > sizeof(number)*8 if you want all the bits (though you'd need to define a > separate method for BigInt), or count_ones(number) if you want the 1 bits. >
