How to dtermine if num is a power of 2

Hi All
How to determine if a given number n is a power of 2
thanks
bib

Assuming you are talking about integers.
public static boolean isPowerOfTwo(int i) {
if (i < 1) return false;
i = ((0xAAAAAAAA & i) >> 1) + (0x55555555 & i);
i = ((0xCCCCCCCC & i) >> 2) + (0x33333333 & i);
i = ((0xF0F0F0F0 & i) >> 4) + (0x0F0F0F0F & i);
i = ((0xFF00FF00 & i) >> 8) + (0x00FF00FF & i);
i = ((0xFFFF0000 & i) >> 16) + (0x0000FFFF & i);
return i == 1;
IMO, this seems a bit easier
int y = (int)(Math.pow((int)Math.sqrt(x),2));
if(y == x)

Similar Messages

  • HT4528 I would like to know how much it costs to repair a power button on an iphone 5?

    I would like to know how much it costs to repair a power button on an iphone 5?

    https://ssl.apple.com/support/iphone5-sleepwakebutton/

  • TS3212 how to reset my iphone 3gs without power of batery ?

    how to reset my iphone 3gs without power of batery?

    Your phone has "told" you it was dying; you didn't listen.  You ignored the broken power button, you ignored the frequent crashing, and now your battery is probably dead.  And despite this, you never thought to import the "important" pictures and data off your phone?
    If you cant turn on the phone or get it recognized in iTunes, there's no way to access the data. 

  • How to export a PowerView report to Power Point in SharePoint Online? If it cannot be done,what is the alternative?

    How to export a PowerView report to Power Point in SharePoint Online? If it cannot be done,what is the alternative?

    Hi Tanay,
    I am not aware of a control you can put in PowerPoint, however, you can insert a web browser control and reference a page in SPO (or maybe even directly the path to the workbook, didn't try that).
    if you are using PowerPoint 2013 take a look
    here
    GALROY

  • I have a new time capsule how do you turn up the transmitting power for wifi

    I have a new time capsule how do you turn up the transmitting power?

    Transmit Power is set by default at 100%, the maximum allowed by law. 
    There are no settings to allow higher output.

  • How do i find words, excel and power point in my mac book air ?

    how do i find words, excel and power point in my mac book air ?

    You would have to purchase, install, and update them first.
    They would be installed into /Applications, probably into an MS Office folder. The installer may have placed aliased copies of the icons in your Dock, or if not, use the Finder > Go menu > Applications, and have a look around. When you find the applications, you can drag/drop the principal three onto your Dock — where a single click can launch them.

  • Can anyone tell me how to correct error code 108 in power point

    Can anyone tell me how to correct error code 108 in power point?
    It appears that a PP presentation has completely disappeared, giving only the error that the file has been deleted or moved (which it hadn't). Is there a way to retrieve it.
    It is visible in 'All my Files' but when clicked says that PP cannot be opened
    Thanks for your help.

    You might try looking/posting here.
    Microsoft Support – Office for Mac
    Microsoft Support – Office for Mac (2)

  • How can I uninstall conduit from my power mac?

    How can I uninstall conduit from my power mac, and keep it off

    Adware removal Conduit
    http://www.thesafemac.com/arg-conduit/
    Best.

  • How do I back up my G4 power book to a Ipod is this possible

    How do I back up my G4 power book to a Ipod is this possible , If so what program would I need. Thank you Dan

    Enable disk use for the iPod, and then open the Users folder on your hard disk and drag your home folder to the iPod. You can back up other applications and documents you've placed on the hard disk in the same way; this method cannot be used to back up a Mac OS X installation.
    (16899)

  • HT204053 How I can change my apple purchase power through visa c.c to non ?

    How I can change my apple purchase power through visa c.c to non ?

    If you're asking how to have an Apple ID without a credit card for purchasing fee apps and media, you have to create a new ID as explained here: http://support.apple.com/kb/ht2534.  Be sure to follow this guide exactly.  Note that you have to start by download and installing a free app before creating the ID.  Once you have the new ID, go to Settings>iTunes & App Stores, tap the existing ID, sign out, then sign in with your new ID.

  • How to Empty all rows within a Power Pivot Model

    Hi,
    I would like to know how to empty all rows within a Power Pivot model. I am in the process of creating quite a complex Power Pivot model. This means I need to create some sort of primitive version control process, e.g. stored multiple backups of the Power
    Pivot model without the data.
    Kind Regards,
    Kieran.
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Forget what I've said before:
    Have a look at Gil's thread here:
    https://social.technet.microsoft.com/Forums/en-US/40abe021-1abd-4a2a-bf33-a035847fb7be/disconnect-datamodel-from-source?forum=powerquery
    For Power Pivot it means that you can get rid of all your data, but Keep Relations, measures, ..everything.
    Just import your tables once in order to get the connections right and move on.
    Imke

  • How can I activate macros in office power point 2008?

    how can I activate macros in office power point 2008?
    thanks in advance for your help.

    As Office is not an Apple product, I strongly recommend asking in the Microsoft Office:Mac forums here:
    Office for Mac forums
    Everyone there is a Mac user AND an Office user, something you can't say about Apple's forums. You will get the fastest help there and I think you will find the contributors more than helpful.
    As I recall, macros were stripped From Office 2008, but you'll get the most definitie answer in the forums I linked for you.

  • How can i turn num lock off?

    How can i turn num lock off?
    It's really annoying when i try to add anything to the middle of sentences it erases the preceding letter.
    I can't find the key on my keyboard and can't find it in keyboard settings either.
    Thank you

    Hi
    Do you use MS Word?
    If yes, then you should disable the overtype function. You can see it marked as OVR.
    Double click on this shortcut and you will be able to disable this.
    Greets

  • TS3274 how do I get my iPad to power off. It just keeps spinning.

    how do I Get my iPad to power off?  It just keeps spinning.

    Try here:
    iOS: Not responding or does not turn on
    If not successful, let the battery fully drain. After charging for at least an hour try again.

  • How to turn on num lock on apple keyboard, how to turn on num lock on apple keyboard

    how to turn on num lock on apple keyboard, how to turn on num lock on apple keyboard

    If you have the wired keyboard that has a 10 keypad there is no numlock. Please when posting be specific, IOS 7.1.1 does not run on Mac computers, what version of OS X is installled and exactly which keyboard are you referring to?

Maybe you are looking for

  • Ask the Cisco VIP: Troubleshooting SIP in Cisco Unified communications

    Troubleshooting SIP in Cisco Unified communications deployments with Cisco VIP Ayodeji Okanlawon This is a Q&A Ask the Expert Session continuation from the Live Webcast Ask your questions on Session Initiation Protocol (SIP) and how it is redefining

  • ALE -- E-Recruitment

    We are implementing E-Rec on EhP4, WD4A. We are planning a 3 tier implementation. Are there documents about the ALE & IDOCS process for these two scenarios -- Transfer employees as internal candidates (what is the triggering point, for example?) -- T

  • OWB : source_import_task component task not work properly ?

    Hi, My config is : OWB 11.2.0.3, Windows XP, 32bit client, to REHL6 64bit database server. I have an 'expert' which makes use of the 'source_import_task' component, but this produces an empty 'OWB Error' dialogue immediately the 'expert' is started.

  • Trying to transfer Hi-MiniDisc files to my MacBook Pro

    Hi,I have a Hi-MiniDisc MZ-NH700 with a lot of music,and I´m trying to transfer it to my Macbook Pro with an OS X Lion 10.7.4 software. I connect the Hi-MiniDisc via USB port but my Mac didn´t detect it...do I need something to make it work? ...anybo

  • Wiki Pages

    Where do I find wiki pages offline. Because I dont have internet all the time. Do we get any zip file of all the wiki pages so that we can read them later santhosh