home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / hp48 / 6430 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.3 KB

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