delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/05/25/04:17:53

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Wed, 25 May 2005 10:49:15 +0300
From: alexbodn AT 012 DOT net DOT il
Subject: Re: to check given no. is power of 2
To: djgpp AT delorie DOT com
Message-id: <5dcec181a17.4294582b@default.domain>
MIME-version: 1.0
X-Mailer: Sun Java(tm) System Messenger Express 6.1 HotFix 0.05 (built Oct 21
2004)
X-Accept-Language: en
Reply-To: djgpp AT delorie DOT com

/*cheching whether num is a power of 2*/
int is_pow2(int num)
{
    while (num > 0)
    {
        if (num % 2)
            num /= 2;
        else break;
    }
    return num == 0;
}

----- Original Message -----
From: aveo <rahul DOT h AT gmail DOT com>
Date: Wednesday, May 25, 2005 7:57 am
Subject: to check given no. is power of 2

> hi all
> i need a C code that checks given no. is power of 2 or not without
> checking any condition.
> 
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019