title: In VHDL ..... how to count leading zeros of vector?
body: <p>I'm working in a VHDL project and I'm facing a problem to calculate the length of vector. I know there is length attribute of a vector but this not the length I'm looking for. For example, I have <code>std_logic_vector</code></p>
  
  <pre><code>    E : std_logic_vector(7 downto 0);  
  </code></pre>
  
  <p>then</p>
  
  <pre><code>    E &lt;= "00011010";
  </code></pre>
  
  <p>so, <code>len = E'length = 8</code> but I'm not looking for this. I want to calculate <code>len</code> after discarding the left most zeros , so <code>len = 5;</code></p>
  
  <p>I know that I can use for loop by checking "0"s bits from left to right and stop if "1" bit occur. But that's not efficient, because I have 1024 or more of bits and that will slow my circuit. So is there is any method or algorithm to calculate the length in efficient way? Such as using combinational gates of log(n) level of gates, ( where n = number of bits ). </p>