11-16-2022, 11:39 PM
(11-16-2022, 11:06 PM)RhoSigma Wrote: Your problem is not the NOT, but the AND, and you overlook only 1 AND 1 = 1.
Output 3:
(NOT 10) AND (NOT 15)
= (-11) AND (-16)
= (11110101) AND (11110000)
= 11110000 = -16
The last four bits result into 0s because only 1 AND 1 = 1, not 1 AND 0 and not 0 AND 1 either.
It's exactly as Rho describes here.
Code: (Select All)
Screen _NewImage(640, 480, 32)
Dim As Integer a(1 To 4), a, b
a(1) = 10
a(2) = 20
a(3) = 40
a(4) = 15
For i = 1 To 4
a = a(i) 'for lazy typing
Print a, Not a, _Bin$(Not a)
Next
Sleep
Print
For i = 1 To 4
For j = 1 To 4
a = Not (a(i)): b = Not (a(j))
Print "NOT "; a(i); "AND NOT "; a(j); " = "; a And b, _Bin$(a And b)
Next
Sleep
Print
Next
When you see the binary values of the number printed out, you can then look up and compare them bit by bit and see why they produce the answer they do.
-11 gives you 11110101 in binary.
-16 gives you 11110000 in binary.
AND those ======== in binary
11110000
From the right to the left:
1 and 0 = 0
0 and 0 = 0
1 and 0 = 0
0 and 0 = 0
1 and 1 = 1
1 and 1 = 1
1 and 1 = 1
1 and 1 = 1
11110000 = -16, in binary.