> > 2. bitwise test for bit value 1
> > bit_onep(8,3) => true
>
> I think I'd prefer to define bit_onep(x,i) so that for integer x it
> is
> the same as bit_and(x,2^i)=1. This gives bit_onep(8,2) => true.
Mmmh? 8=2^3. I can't follow here.
> Bit_onep extends naturally to all real numbers: bit_onep(0.5,-1)
> =>
> true; bit_onep(%pi,-1)=>false, etc.
I know you are in favour of extending these functions. But today I regard these extensions
as future plans.
> Some more simplifications
> bit_onep(oddnum,0) => true; evennum,0 => false
> bit_onep(k^n,m) => true if (NOT iff) m=n*log(k)/log(2)
> bit_onep(x,n) where 0<=x<2^n => false
Thank you for this. I will try to code it.
> > 3. bitlength
> > bit_length(8) => 4
> OK, == floor(log(x)/log(2)) for x>0, right?
No, 8=1000
and floor(log(8)/log(2)) = 3
I think
bit_length(x)== floor(log(x)/log(2)) + 1 for x>0
By the way, there is a floor bug:
(%i1) floor(log(8)/log(2));
(%o1) 2
(%i2) float(log(8)/log(2));
(%o2) 3.0
> Additional simplification
> bit_length(2^n) => n (n>=0) (also 4^n=>2*n, etc.)
Thank you for this. I will try to code it.
But again, I think it's
bit_length(2^n) => n +1 (n>=0) (also 4^n=>2*n+1, etc.)
Volker