News:

  • June 29, 2026, 10:06:53 PM

Login with username, password and session length

Author Topic: ENCO in MATH box  (Read 7742 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
ENCO in MATH box
« 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.
« Last Edit: August 21, 2014, 08:01:31 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: ENCO in MATH box
« Reply #1 on: August 21, 2014, 11:11:04 PM »
Oh, and I assume 1 << x is probably faster than 2**x?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: ENCO in MATH box
« Reply #2 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.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: ENCO in MATH box
« Reply #3 on: August 22, 2014, 10:10:56 AM »
Thank you!
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: ENCO in MATH box
« Reply #4 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.
« Last Edit: January 30, 2015, 01:03:21 AM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.