TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: All
from: Bob Stout
date: 2004-06-04 02:05:52
subject: Re: [C] C Puzzles

From: Bob Stout 

On Wed, 2 Jun 2004, Bruce D. Wedding wrote:

> 3. Find if the given number is a power of 2.

This one's in SNIPPETS

----[ snip ]----
#include 
#include "snipmath.h"

int ispow2(int x)
{
      return! ((~(~0U>>1)|x)&x -1) ;
}

#ifdef TEST

int main(void)
{
      int i;

      for (i = 0; i < 256; ++i)
            printf("%3d: %d\n", i, ispow2(i));
      return 0;
}

#endif /* TEST */
----[ snip ]----

-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/ Web graphics development:
http://Image-Magicians.com/ Software archives:
http://snippets.snippets.org/
  c.snippets.org/   cpp.snippets.org/      java.snippets.org/
  d.snippets.org/   python.snippets.org/   perl.snippets.org/
  dos.snippets.org/ embedded.snippets.org/ apps.snippets.org/
Audio and loudspeaker design:
  http://LDSG.snippets.org/   http://www.diyspeakers.net/

--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.