What is an equation to find the largest power of 2 less than or equal to integer n using basic operators, ie, +-*/^ logic gates mod rem?
Printable View
What is an equation to find the largest power of 2 less than or equal to integer n using basic operators, ie, +-*/^ logic gates mod rem?
Write out some numbers in binary.
Write out some powers of two less than that, in binary.
Notice anything?
Yep, I'm having trouble making that into an equation though.
I also meant less than or equal to an integer n.
So basically its 2^(position of leftmost 1 in binary) but I don't know how to make that into an equation just using n and basic operators. This is for VHDL so any operators there are allowed.
Learn how to compute a binary logarithm, it will help.
You can shift left once each cycle, keep a counter, until you get a 1 on the MSB.
A single cycle circuit may be huge (I'm not sure).