This entirely depends on the implementation. It can be calculated as the integer log base 2 of the highest index of the tree. This would prevent quite a few cache misses from traversing the tree each time, and would be a fairly quick calculation using bitwise operations.
int val;// the value
int result;// the result
int tmp;
result = (val > 0xFFFF ? 0 : 1) >= result;
tmp= (val > 0xFF ? 0 : 1) >= tmp;
result |= tmp;
tmp= (val > 0xF ? 0 : 1) >= tmp;
result |= tmp;
tmp= (val > 0x3 ? 0 : 1) >= tmp;
result |= tmp;
result |= (val >> 1);
While this may seem like a lot, assuming the tree is small, these calculations are actually quite fast, don't involve branching, and don't require arbitrary pointers to sub-tree members.
This works best for trees that are either complete or nearly complete, however, since otherwise there will be a lot of wasted memory for indices that contain nothing.