Page 1 of 2
byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 7:48 am
by funkheld
hello, good day.
byte from 0-255 , create byte from 255-0 with overflow with basic
I need a quick byte command please that goes from an integer number of basic from 0-255 and then starts again at 0 when the value 255 is reached, the same if 255-0 at 0 starts again at 255.
Thanks.
greeting
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 7:59 am
by ahenry3068
funkheld wrote: ↑Tue Mar 26, 2024 7:48 am
hello, good day.
byte from 0-255 , create byte from 255-0 with overflow with basic
I need a quick byte command please that goes from an integer number of basic from 0-255 and then starts again at 0 when the value 255 is reached, the same if 255-0 at 0 starts again at 255.
Thanks.
greeting
I don't know if this is what you want.
Byte.Var = 0
LOOP:
IF Byte.Var = 0 THEN LOCATE 2,2:PRINT " ";
LOCATE 2,2:PRINT Byte.Var
SLEEP 10
GOSUB INC.BYTE.VAR
GOTO LOOP
INC.BYTE.VAR:
Byte.Var = Byte.Var + 1
IF Byte.Var > 255 THEN Byte.Var = 0
RETURN
DEC.BYTE.VAR:
IF Byte.Var = 0 THEN Byte.Var = 255:RETURN
Byte.Var = Byte.Var - 1
RETURN
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 3:48 pm
by TomXP411
Normally, you'd use the Modulo operator for that, but BASIC 2 doesn't have one.
There's no simple way to do this in BASIC 2, so you'll probably have to do it the hard way.
Counting up...
X = X + 1:IF X>255 THEN X=0
Counting down
X = X-1:IF X<0 THEN X=255
Or you can use FOR loops
FOR X = 0 TO 255
do stuff
NEXT
FOR X=-255 TO 0 STEP -1
do stuff
NEXT
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 5:40 pm
by funkheld
hello thanks for info.
with basic z is not 0 but z=0.0000001...
greeting
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 5:46 pm
by ahenry3068
funkheld wrote: ↑Tue Mar 26, 2024 5:40 pm
z=byte ( 0-255)
I'm looking for something similar and short for basic please
if here z>255 then z becomes byte 0
if z<0 here then z becomes byte 255
with basic z is not 0 but z=0.0000001...
Tom and I have both shown you the only way to do it in BASIC 2.0
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 5:48 pm
by funkheld
Modulo not in basic from x16.
----------------------------
Tom and I have both shown you the only way to do it in BASIC 2.0
----------------------------
I thought there was a magic box somewhere for something quick on the x16.
thanks
greeting
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 5:51 pm
by ahenry3068
funkheld wrote: ↑Tue Mar 26, 2024 5:48 pm
Modulo not in basic from x16.
----------------------------
Tom and I have both shown you the only way to do it in BASIC 2.0
----------------------------
I thought there was a magic box somewhere for something quick on the x16.
thanks
greeting
A lot of things in this version you must do the Hard way. This is one of them.
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 5:52 pm
by ahenry3068
If you use a GOSUB Like I did above it can at least hide the details from your Main Code.
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 6:13 pm
by desertfish
what about just anding with 255
10 I=0
20 PRINT I,
30 I=(I+1) AND 255
40 GOTO 20
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
Posted: Tue Mar 26, 2024 6:34 pm
by ahenry3068
funkheld wrote: ↑Tue Mar 26, 2024 5:48 pm
Modulo not in basic from x16.
----------------------------
Tom and I have both shown you the only way to do it in BASIC 2.0
----------------------------
I thought there was a magic box somewhere for something quick on the x16.
thanks
greeting
Desertfish is absolutely correct I=(I+1) AND 255 will loop it back to 0. Wish I had thought of that first. That's as close as a Magic Bullet as your going to GET. It's almost certainly a little faster than the if/then.
Could also be written as i=(i+1) AND $FF (This is not different than above, Just using Hexidecimal notation. )