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

Title: ENCO in MATH box
Post 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.
Title: Re: ENCO in MATH box
Post by: Controls Guy on August 21, 2014, 11:11:04 PM
Oh, and I assume 1 << x is probably faster than 2**x?
Title: Re: ENCO in MATH box
Post by: franji1 on August 22, 2014, 08:56:54 AM
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.
Title: Re: ENCO in MATH box
Post by: Controls Guy on August 22, 2014, 10:10:56 AM
Thank you!
Title: Re: ENCO in MATH box
Post by: Controls Guy on January 30, 2015, 12:20:46 AM
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.