EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Select MS Bit from an integer
From: Till Straumann <[email protected]>
To: "Dudley, David" <[email protected]>, "[email protected] >> EPICS Techtalk" <[email protected]>
Date: Fri, 4 Sep 2015 09:12:19 -0700
You could do it with a bunch of calc (C1..C5, V) records

 C1 computes  (IN & 0xffff0000)
 C2 computes  (c1 ? c1 : IN ) & 0xff00ff00
 C3 computes  (c2 ? c2 : c1 ? c1 : IN) & 0xf0f0f0f0
 C4 computes  (c3 ? c3 : c2 ? c2 : c1 ? c1 : IN) & 0xcccccccc
 
C5 computes  (c4 ? c4 : c3 ? c3 : c2 ? c2 : c1 ? c1 : IN) & 0xaaaaaaaa

V computes  (C1 ? 16 : 0) + (C2 ? 8 : 0) + (C3 ? 4 : 0) + (C4 ? 2 : 0) + (C5 ? 1 : 0)

HTH
- Till

On 09/04/2015 07:59 AM, Dudley, David wrote:

Quick question that I didn’t see an immediate way to perform

 

How do I select the most-significant set bit in an integer?  I was thinking about using a SEL, but that seems like a lot of work just to do a simple thing.  Other possibility would be a SUB, but I’d like to do it with base record types if I can.

 

Something simple please…

 

L


Replies:
Re: Select MS Bit from an integer Andrew Johnson
References:
Select MS Bit from an integer Dudley, David

Navigate by Date:
Prev: Select MS Bit from an integer Dudley, David
Next: Re: Select MS Bit from an integer Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Select MS Bit from an integer Dudley, David
Next: Re: Select MS Bit from an integer Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 16 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·