To create a value 2^k, you can just say (1 << k).  I need the inverse
function.

Given a value 2 ^ k, does anyone know how to efficiently extract k
(other than a shift loop?)

---------------------------------------------------
In return for reading my email, here's an algorithmic goodie for you:

To answer the question:  Is the memory address, A,  N-byte aligned?
you ask

if (!(long(A) & (N-1)))

To make A N-byte aligned, you say
A = alloc(length + N - 1);
A' = (long(A) + N-1) & ~(N-1);

You knew that.

But do you know how to answer the question, "what IS the byte alignment
of address A?"

The answer is:
byte alignment = A & -A; // cast A to unsigned value

For example, 1536 &-1536 = 256,  1152 & -1152 = 128, etc....

(In the windows calculator, you can perform unsigned(-X) by typing in -X
and hitting Hex, Dec.)



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to