NOT Problem
#6
(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.  Smile
Reply


Messages In This Thread
NOT Problem - by Kernelpanic - 11-16-2022, 09:52 PM
RE: NOT Problem - by mnrvovrfc - 11-16-2022, 10:25 PM
RE: NOT Problem - by Jack - 11-16-2022, 10:56 PM
RE: NOT Problem - by RhoSigma - 11-16-2022, 11:06 PM
RE: NOT Problem - by SMcNeill - 11-16-2022, 11:39 PM
RE: NOT Problem - by CharlieJV - 11-16-2022, 11:58 PM
RE: NOT Problem - by bplus - 11-16-2022, 11:36 PM
RE: NOT Problem - by Jack - 11-16-2022, 11:41 PM
RE: NOT Problem - by bplus - 11-16-2022, 11:43 PM
RE: NOT Problem - by Kernelpanic - 11-17-2022, 09:41 PM



Users browsing this thread: 3 Guest(s)