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?
This is a discussion on Largest Power of 2 below a number n within the Tech Board forums, part of the Community Boards category; What is an equation to find the largest power of 2 less than or equal to integer n using basic ...
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?
Last edited by Blasz; 05-05-2011 at 02:02 AM.
Write out some numbers in binary.
Write out some powers of two less than that, in binary.
Notice anything?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
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).