Post Reply 
(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
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (11C) Very fast binary converter + fast modulo - Dieter - 03-16-2018 01:08 PM



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