source: buchla-68k/lib700/ispow2.c@ f40a309

Last change on this file since f40a309 was f40a309, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Unix line breaks.

  • Property mode set to 100644
File size: 880 bytes
Line 
1/*
2 =============================================================================
3 ispow2.c -- fast test to see if X is a power of 2
4 Version 2 -- 1989-01-24 -- D.N. Lynx Crowe
5
6 Returns:
7
8 TRUE if X is a power of 2,
9 FALSE otherwise.
10 =============================================================================
11*/
12
13#include "stddefs.h"
14
15short
16ispow2(x)
17register long x;
18{
19 register short i;
20 register long k;
21
22 k = 0x00000001L; /* setup the bit mask in k */
23
24 for (i = 32; i--; ) { /* check each bit in x ... */
25
26 if ((x & k) NE 0L) { /* ... for the 1st 1 and ... */
27
28 if ((x & ~k) NE 0L) /* ... if there are others ... */
29 return(FALSE); /* ... it's not a power of 2 */
30 else /* ... otherwise .. */
31 return(TRUE); /* ... it is a power of 2 */
32 }
33
34 k = k << 1; /* examine the next position */
35 }
36
37 return(FALSE); /* no bits on isn't a power of 2 */
38}
Note: See TracBrowser for help on using the repository browser.