a bit of a maths question

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
the7778
Posts: 14
Joined: Sat Oct 05, 2019 5:14 pm

a bit of a maths question

Post by the7778 »

i know this is a bit of a maths question but how to i find the decimal opposite of an 8 bit binary number? like inverting all the bits? so say 255 becomes 0 and 0 becomes 255.

like 11111111
00000000
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: a bit of a maths question

Post by dr beep »

In machinecode with XOR 255
This will swap all 1 to 0 and 0 to 1.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: a bit of a maths question

Post by XavSnap »

:lol:

Code: Select all

5 input x
10 LET 255-x

Code: Select all

5 REM XOR 255
10 LET A$="HELLO WORLD"
20 FOR A=1 TO LEN A$
30 LET A$(A)=CHR$(255-CODE A$(A))
40 NEXT A
45 PRINT A$
50 FOR A=1 TO LEN A$
60 LET A$(A)=CHR$(255-CODE A$(A))
70 NEXT A
80 PRINT A$
Have fun.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
the7778
Posts: 14
Joined: Sat Oct 05, 2019 5:14 pm

Re: a bit of a maths question

Post by the7778 »

ok, ty


and what about mirroring?
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: a bit of a maths question

Post by XavSnap »

Yes, next tread…
:geek:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply