05-23-2013 09:59 AM
I know how to get the property node; now if someone could just tell me how to make a global....
05-23-2013 03:50 PM - edited 05-23-2013 04:02 PM
@for(imstuck) wrote:
Is there a way to "get number of bits in integer without converting to string first" without converting to a string first to use the string length function?
Number of bits that represent a given integer?
floor( log2( n ) ) + 1;
Where n is the number you're determining the bit length of. floor() is the floor() function, which literally drops the decimal (with no rounding). log2 calculates the binary logarithm (log with base 2) and 1, well, is the loneliest number.
The secret here is that you don't care about any binary bit except the highest order bit with a 1, and its "position" tells you exactly how many bits (minus 1) you need to represent that number. Binary positions are represented as 2^n, and the reverse is log2 - so the whole digit in the log2 calculation tells you the position of the highest-order bit, and everything else is just fluff.
EDIT: LOL, I almost forgot to add 1. When we say how many bits we're using, we're 1-based, not zero-based, so bit position only gives us "almost" the full answer... 🙂
-Danny
05-23-2013 05:41 PM
I am pretty sure if he tries that formula out on -1 he is going to encounter an out of memory error somewhere.
I think he wants the bits in his chosen representation, not a given value.