byte from 0-255 , create byte from 255-0 with overflow in the basic

All aspects of programming on the Commander X16.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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
User avatar
ahenry3068
Posts: 1147
Joined: Tue Apr 04, 2023 9:57 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post by funkheld »

hello thanks for info.

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.
User avatar
ahenry3068
Posts: 1147
Joined: Tue Apr 04, 2023 9:57 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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
Last edited by funkheld on Tue Mar 26, 2024 5:51 pm, edited 1 time in total.
User avatar
ahenry3068
Posts: 1147
Joined: Tue Apr 04, 2023 9:57 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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.
User avatar
ahenry3068
Posts: 1147
Joined: Tue Apr 04, 2023 9:57 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post by ahenry3068 »

If you use a GOSUB Like I did above it can at least hide the details from your Main Code.
User avatar
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

Post by desertfish »

what about just anding with 255
10 I=0 20 PRINT I, 30 I=(I+1) AND 255 40 GOTO 20
User avatar
ahenry3068
Posts: 1147
Joined: Tue Apr 04, 2023 9:57 pm

Re: byte from 0-255 , create byte from 255-0 with overflow in the basic

Post 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. )
Post Reply