(11C) (15C) Very fast binary converter + fast modulo
03-16-2018, 01:08 PM (This post was last modified: 03-16-2018 01:10 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (11C) Very fast binary converter + fast modulo
(03-14-2018 10:07 PM)michaelzinn Wrote:  This program can convert numbers to binary quickly by using a lookup table to convert 4 bits at once.

That's a nice idea which results in a significantly faster program.

(03-14-2018 10:07 PM)michaelzinn Wrote:  Internally, it also uses a fast modulo calculation.

The program uses this routine at LBL D for calculating x mod 2. This works well with the implemented method, calculating 2 · frac(x/2), but it's not a good idea for a general modulo function: try 25 mod 7 to get 3,999999997 instead of 4.

A better method for a mod b is  a – b · int(a/b):

Code:
LBL D X<>Y STO .7 X<>Y / LastX X<>Y INT x RCL .7 X<>Y – RTN

Of course this is slower than the frac method, but it yields better results.

If you want to stay with the original method: this can be done without using a data register:

Code:
LBL D / LastX X<>Y FRAC x RTN

Oh, I just notice this is your first post here. So, welcome to the forum. :-)

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread (11C) (15C) Very fast binary converter + fast modulo - Michael Zinn - 03-14-2018, 10:07 PM RE: (11C) Very fast binary converter + fast modulo - Dieter - 03-16-2018 01:08 PM RE: (11C) Very fast binary converter + fast modulo - Michael Zinn - 03-17-2018, 06:06 PM RE: (11C) Very fast binary converter + fast modulo - Dieter - 03-17-2018, 09:17 PM RE: (11C) (15C) Very fast binary converter + fast modulo - Steve Simpkin - 03-03-2024, 07:25 PM RE: (11C) Very fast binary converter + fast modulo - Gene - 03-16-2018, 03:47 PM RE: (11C) Very fast binary converter + fast modulo - Michael Zinn - 03-18-2018, 12:14 AM RE: (11C) (15C) Very fast binary converter + fast modulo - johnb - 03-03-2024, 08:53 PM RE: (11C) (15C) Very fast binary converter + fast modulo - John Keith - 03-03-2024, 10:34 PM RE: (11C) Very fast binary converter + fast modulo - Michael Zinn - 04-05-2018, 03:25 PM RE: (11C) (15C) Very fast binary converter + fast modulo - Thomas Klemm - 03-03-2024, 09:39 AM RE: (11C) (15C) Very fast binary converter + fast modulo - Thomas Klemm - 03-03-2024, 09:01 PM RE: (11C) (15C) Very fast binary converter + fast modulo - Steve Simpkin - 03-03-2024, 09:15 PM RE: (11C) (15C) Very fast binary converter + fast modulo - Thomas Klemm - 03-03-2024, 10:51 PM

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