Code to find greatest power of 2 below given number

I am working on a project where I need to convert Decimal numbers to binary. In this code I need to write code that finds the greatest power of 2 that is below the number the user entered. I havent made it too far into the code or I would copy paste what I have so far. Anyone have any ideas on what to write to make code that can execute this task?

The given decimal is named int DeciAmount.

Re: Code to find greatest power of 2 below given number

You still need to copy and paste whatever you have. There are various ways of finding that information out. Using logarithms is one way. Another way is to use a for loop. If you know that then you know how to find the largest power of 2 less than the number.

Regards,

Jim

Re: Code to find greatest power of 2 below given number

How would you do this if you were doing it on paper? (Hint: What do you notice about binary numbers that are powers of two?)

Re: Code to find greatest power of 2 below given number

Should that power of two be strictly less than a number n? e.g. PO2(4) == 2?

kind regards,

Jos