Post Reply 
Bits of integer
12-06-2022, 09:34 PM
Post: #14
RE: Bits of integer
(12-06-2022 07:26 PM)robve Wrote:  Very nice. But you can avoid divisions (right shifts) solely by using multiplications (left shifts).

Yes, it can be done this way too.

The problem is, for HP71B, *both* multiply and divide are costly.
Divide a bit worse, but it is in the same ballpark.

Programming in interpreted BASIC is very different than compiled languages.

Also, pow-of-2 and pow-of-10 numbers never match (except for 2^0 = 10^0 = 1)
This required an extra step to correct for the boundary. (bolded line)

Below could optimize a bit, but likely still slower than binary search with DIV (9.97 seconds)

Time = 11.55 seconds Wrote:10 DESTROY ALL @ RANDOMIZE 1 @ T=0 @ SETTIME 0
20 FOR I=1 TO 10000 @ T=T+FNB(IP(RND*999999999999)+1) @ NEXT I
30 DISP T,TIME

100 DEF FNB(X) @ B=40 ! FNB(x >= 2^39) assumed 40
110 Y=X*4294967296 @ IF Y<1E12 THEN X=Y @ B=B-32
120 Y=X*65536 @ IF Y<1E12 THEN X=Y @ B=B-16
130 Y=X*256 @ IF Y<1E12 THEN X=Y @ B=B-8
140 Y=X*16 @ IF Y<1E12 THEN X=Y @ B=B-4
150 Y=X*4 @ IF Y<1E12 THEN X=Y @ B=B-2
160 Y=X*2 @ IF Y<1E12 THEN X=Y @ B=B-1
170 FNB=B-(X<549755813888)
180 END DEF
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)