Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

log2(n) in Verilog without using +, -, *, /, ** or $clog2

Status
Not open for further replies.

Đô Đô

Newbie level 4
Joined
Apr 8, 2022
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
I'm trying to write Verilog code to compute a base 2 log value of x, where x is an unsigned 16 bit number. At my teacher's request, I can't use Verilog's built-in function ($clog2) or built-in math operations like *, /, +, -, **. So it gives me a lot of trouble. Please help.
 

Hi,

What input range?
(What output range?)
What precision?

If you are interested in integer output, then just return the position of the most left (MB) "1" in the input data.

Examples:
* input 8 = 0x08 = 0b00001000
In the binary representation the "1" is at bit3 --> the result is 3

* input is 128 --> 0b10000000 --> the "1" is at bit7 --> the result is 7

Klaus
 
  • Like
Reactions: Đô Đô

    Đô Đô

    Points: 0
    Oh that's great, so what's the working principle for it?. And how am I going to do that? I am a beginner. Thank you
Hi,

What input range?
(What output range?)
What precision?

If you are interested in integer output, then just return the position of the most left (MB) "1" in the input data.

Examples:
* input 8 = 0x08 = 0b00001000
In the binary representation the "1" is at bit3 --> the result is 3

* input is 128 --> 0b10000000 --> the "1" is at bit7 --> the result is 7

Klaus
Oh that's great, does this apply to numbers that are not divisible by 2, if i just take the integer ? So what's the working principle for it ?. And how am I going to do that? I am a beginner. Thank you
 
Last edited:

Hi,

what about my questions?
Did you try/read/draw something on your own?

Klaus
 

Consider that the purpose may be to merge two unrelated math calculations into one exercise:

(a) how to express fractions in base 2 (besides integers),

(b) how to approach logarithms in base 2. (And the counterpart which is exponents containing fractions.)

I suspect the teacher wishes not for a 'pat answer' from a message board, but your own expansion on concepts learned in school normally in base ten.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top