Logarithm in Verilog

Max Eastman picture Max Eastman · Apr 9, 2011 · Viewed 25.9k times · Source

I've a statement in verilog looking like integer level = log(N) (Where N is a parameter and level is to be determined) But I understand I cannot do complex math statements in verilog, so I'm wondering if there is an alternative solution to the above problem?

Any feedback appreciated!

Answer

abettino picture abettino · Aug 31, 2011

If it is a logarithm base 2 you are trying to do, you can use the built-in function $clog2().