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
byte from 0-255 , create byte from 255-0 with overflow in the basic
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
I don't know if this is what you want.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
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
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
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
hello thanks for info.
with basic z is not 0 but z=0.0000001...
greeting
with basic z is not 0 but z=0.0000001...
greeting
Last edited by funkheld on Tue Mar 26, 2024 5:50 pm, edited 1 time in total.
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
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
----------------------------
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
Last edited by funkheld on Tue Mar 26, 2024 5:51 pm, edited 1 time in total.
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
A lot of things in this version you must do the Hard way. This is one of them.
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
If you use a GOSUB Like I did above it can at least hide the details from your Main Code.
- desertfish
- Posts: 1098
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
what about just anding with 255
10 I=0 20 PRINT I, 30 I=(I+1) AND 255 40 GOTO 20
10 I=0 20 PRINT I, 30 I=(I+1) AND 255 40 GOTO 20
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: byte from 0-255 , create byte from 255-0 with overflow in the basic
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. )