Post Reply 
Bits of integer
12-17-2022, 02:31 AM
Post: #42
RE: Bits of integer
(12-13-2022 02:37 AM)Joe Horn Wrote:  Here's a brute-force implementation of that method:

LBL A, 0, STO I, Rdn, LBL 0, g ISZ, f SR, g x≠0, GTO 0, RCL I, RTN

GSB A in any binary mode returns the number of bits needed to express X.

It works, but it's horrifically slow:
Input 2^40-1 outputs correct result of 40 in 15 seconds. Big Grin
Input 2^40 outputs correct result of 41 in 15 seconds. Big Grin

EDIT: 0 NOT with WSIZE of 64 returns 64 in 22 seconds.

That's not that much for a calculator that came out 40 years ago. My Sanyo (1977) needs more than 30s to compute the factorial of 69!!
I should have bought one 16C when you could find it in stores… Of course, with a DM16L, it would be faster (and it's about half the price).

(12-13-2022 09:17 AM)Joe Horn Wrote:  Here's a 16C-only routine that doesn't require any looping. The LJ command is on the [g] [A] key. #B is on the [g] [7] key.

LJ, 0, NOT, #B, x<>y, –

As before, put any value in X in any binary mode. The above routine returns the number of bits required to express X. If WSIZE is sufficiently large to put X on the stack, then this routine will always return the correct answer.

Inputs of 2^40-1 and 2^40 return the correct answers (40 and 41 respectively) in roughly 1.5 seconds, with a speed hit for a large WSIZE.

I have tried both of your programs at: https://stendec.io/ctb/rpn_prog.html
Thank you! Smile

Too bad the RPL calculators don't have all the functions of the 16C. However, trying to program the missing functions might be a good exercise!

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Bits of integer - Albert Chan - 12-05-2022, 12:12 PM
RE: Bits of integer - Werner - 12-05-2022, 12:41 PM
RE: Bits of integer - J-F Garnier - 12-05-2022, 02:55 PM
RE: Bits of integer - Albert Chan - 12-05-2022, 04:13 PM
RE: Bits of integer - Valentin Albillo - 12-05-2022, 04:29 PM
RE: Bits of integer - J-F Garnier - 12-06-2022, 08:29 AM
RE: Bits of integer - robve - 12-05-2022, 10:06 PM
RE: Bits of integer - Albert Chan - 12-06-2022, 12:15 AM
RE: Bits of integer - John Keith - 12-06-2022, 07:15 PM
RE: Bits of integer - robve - 12-06-2022, 08:15 PM
RE: Bits of integer - Thomas Klemm - 12-06-2022, 07:41 AM
RE: Bits of integer - Albert Chan - 12-06-2022, 06:49 PM
RE: Bits of integer - robve - 12-06-2022, 07:26 PM
RE: Bits of integer - Albert Chan - 12-06-2022, 09:34 PM
RE: Bits of integer - FLISZT - 12-07-2022, 12:52 AM
RE: Bits of integer - Paul Dale - 12-07-2022, 06:33 AM
RE: Bits of integer - J-F Garnier - 12-07-2022, 08:41 AM
RE: Bits of integer - Albert Chan - 12-07-2022, 02:51 PM
RE: Bits of integer - J-F Garnier - 12-10-2022, 09:31 AM
RE: Bits of integer - Joe Horn - 12-07-2022, 07:18 AM
RE: Bits of integer - Werner - 12-07-2022, 08:00 AM
RE: Bits of integer - pinkman - 12-07-2022, 10:13 PM
RE: Bits of integer - mfleming - 12-07-2022, 09:48 PM
RE: Bits of integer - John Keith - 12-11-2022, 09:09 PM
RE: Bits of integer - FLISZT - 12-12-2022, 04:54 PM
RE: Bits of integer - cdmackay - 12-12-2022, 07:28 PM
RE: Bits of integer - FLISZT - 12-12-2022, 08:14 PM
RE: Bits of integer - mfleming - 12-12-2022, 10:07 PM
RE: Bits of integer - Joe Horn - 12-13-2022, 02:37 AM
RE: Bits of integer - Joe Horn - 12-13-2022, 09:17 AM
RE: Bits of integer - mfleming - 12-13-2022, 12:15 PM
RE: Bits of integer - Albert Chan - 12-14-2022, 02:35 PM
RE: Bits of integer - mfleming - 12-14-2022, 11:16 PM
RE: Bits of integer - Gjermund Skailand - 12-14-2022, 09:47 PM
RE: Bits of integer - robve - 12-15-2022, 02:07 AM
RE: Bits of integer - Albert Chan - 12-15-2022, 06:08 AM
RE: Bits of integer - EdS2 - 12-15-2022, 09:06 AM
RE: Bits of integer - Albert Chan - 12-15-2022, 12:29 PM
RE: Bits of integer - mfleming - 12-15-2022, 12:59 PM
RE: Bits of integer - Thomas Klemm - 12-15-2022, 04:08 PM
RE: Bits of integer - Albert Chan - 12-15-2022, 07:44 PM
RE: Bits of integer - FLISZT - 12-17-2022 02:31 AM



User(s) browsing this thread: 1 Guest(s)