Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Controls Guy on August 21, 2014, 07:58:28 PM
-
Is there a way to do ENCO or the equivalent in a MATH expression? (DECO of course is just 2 ** x or 1 << x)
I guess you could do ln(x)/ln(2), or log(x)/log(2), which is equivalent to log2(x), but that would only work on numbers with only a single bit set.
If not, I'd like to put in a request for a MATH version.
-
Oh, and I assume 1 << x is probably faster than 2**x?
-
Oh, and I assume 1 << x is probably faster than 2**x?
Extremely. Hardware accelerated instruction (think a few clocks) vs. a Floating Point library call with all the integer to real and real to integer calls.
We can look into making an ENCODE(value) MATH function.
-
Thank you!
-
OK, so 3.322 * log(D1000) (IOW, log(D1000) / log(2)) assigned to an integer type, does give the position of the highest bit set. Sort of a top to bottom version of ENCO.
I also thought of setting up an array of powers of 2 and using COUNTIFLT/GT.