As 2014 is BASIC's 50th anniversary (and also, if you re-arrange the numbers in the year 2014 you will get 1024 - true fact), I've been doing some basic experiments etc...
Modulo is a pretty useful function in C and C-alike languages, so I thought I'd write something that will do modulo on 8-bit computers.
10 LET Z=0
20 LET R=0
30 LET D=0
40 LET I=0
50 PRINT "PLEASE ENTER A NUMBER FOLLOWED BY THE DIVISOR"
60 INPUT Z
70 INPUT D
80 PRINT Z;"/";D;" = "
90 GOSUB 1000
100 PRINT R;" REMAINDER ";Z
110 STOP
1000 FOR I=1 TO 0 STEP -1
1010 LET Z=Z-D
1020 LET R=R+1
1030 LET I=(Z>=D)
1040 NEXT I
1050 RETURN
It's quite slow but I think the logic is correct.
I've used a FOR loop essentially like a DO/WHILE loop in C/PHP etc... It didn't work at first so I reversed the logic and that seemed to fix it.
Here is the ZX80 version, as I couldn't find the >= on the keyboard, I had a work-around which you'll see once you load the file.
Also, it doesn't handle zero currently. According to the method that I'm employing x/0 is not infinity - it's x remainder infinity - I may add this into V2.
Shaun_B wrote: ↑Tue Mar 28, 2017 2:01 pm
Here is the ZX80 version, as I couldn't find the >= on the keyboard, I had a work-around which you'll see once you load the file.
Also, it doesn't handle zero currently. According to the method that I'm employing x/0 is not infinity - it's x remainder infinity - I may add this into V2.
Regards,
Shaun.
Hi Shaun,
If you're going for fewest bytes, a better of doing Z>=D without >= is just NOT Z<D