home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!news.u.washington.edu!news.uoregon.edu!nntp.uoregon.edu!stevev
- From: stevev@miser.uoregon.edu (Steve VanDevender)
- Newsgroups: comp.sys.hp48
- Subject: Re: Power of 2
- Message-ID: <STEVEV.92Dec20030331@miser.uoregon.edu>
- Date: 20 Dec 92 11:03:31 GMT
- Article-I.D.: miser.STEVEV.92Dec20030331
- References: <921219202242.26018622@CCSUA.CTSTATEU.EDU>
- Organization: University of Oregon Chemistry Stores
- Lines: 20
- NNTP-Posting-Host: miser.uoregon.edu
- In-reply-to: FELSON_ADJ@CCSUA.CTSTATEU.EDU's message of 19 Dec 1992 19:22:42 -0600
-
- Kenneth Cooke writes:
- ! << NOT DUP 1 + OR 1 + #0 == >>
-
- There's an even better solution than this.
-
- \<< # 0h SWAP OVER + DUP 1 - AND == \>>
-
- This works on both real numbers and binary integers, and
- recognizes all powers of 2 less than 10^12 on the HP 48.
-
- Note that for any binary number, subtracting one will toggle the
- bits from the least-significant bit up to the least-significant 1
- bit. Therefore, DUP 1 - AND will strip the least-significant 1
- bit from a binary integer. If a binary integer is a power of
- two, it will have only one 1 bit.
- --
- Steve VanDevender stevev@greylady.uoregon.edu
- "Bipedalism--an unrecognized disease affecting over 99% of the population.
- Symptoms include lack of traffic sense, slow rate of travel, and the
- classic, easily recognized behavior known as walking."
-