Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NOT Problem
#1
The problem with NOT is a hidden error for me. In any case, I personally have no comprehensible explanation for the results. Better for the one result. Why is an incorrect result returned at only one point?

PS: I've now tried everything I could think of again, the wrong result under No. 3 remains.

Code: (Select All)
'NOT-Problem - 16. Nov. 2022

Option _Explicit

Dim As Integer a, b, c, d

a = 10
b = 20
c = 40
d = 15

Print
Print "1"
Print (Not a) And (Not b)

Print
Print "2"
Print (Not c)

Print
Print "3"
Print (Not a) And (Not d)

Print
Print "4"
Print (Not d)

Print
Print "5"
Print (Not b) And (Not c)

End

[Image: NOT-Problem.jpg]
Reply
#2
Where is "(not a) and (not c)"? How about involving "c" and "d" only? You have to complete the test suite...
Reply
#3
Kernelpanic
I don't know what you expect, here's the output from the C equivalent
Code: (Select All)
1
-31
2
-41
3
-16
4
-16
5
-61


Code: (Select All)
#include <stdio.h>
#include <stdint.h>


int main(void) {
    int16_t a=10, b=20, c=40, d=15;
    printf("%s\n","1");
    printf("%d\n",(~a)&(~b));
    printf("%s\n","2");
    printf("%d\n", ~c);
    printf("%s\n","3");
    printf("%d\n",(~a)&(~d));
    printf("%s\n","4");
    printf("%d\n",~d);
    printf("%s\n","5");
    printf("%d\n",(~b)&(~c));
    return 0;
}
Reply
#4
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.
Reply
#5
Code: (Select All)
Option _Explicit
_Title "Naht a problem" ' B+ 2022-11-16
DefLng A-Z
Dim a, b, c
a = 10
b = -20
c = 0

Print
Print "1:  naht(a), naht(b), naht(c)"
Print naht(a), naht(b), naht(c)

Print
Print "2:  Anned&(a, b), Anned&(a, c), Anned&(b, c)"
Print Anned&(a, b), Anned&(a, c), Anned&(b, c)

Print
Print "3: Anned&(naht(a), b), Anned&(naht(a), c), Anned&(naht(b), c) "
Print Anned&(naht(a), b), Anned&(naht(a), c), Anned&(naht(b), c)

Print
Print "4: Anned&(naht(a), naht(b)), Anned&(naht(a), naht(c)), Anned&(naht(b), naht(c)) "
Print Anned&(naht(a), naht(b)), Anned&(naht(a), naht(c)), Anned&(naht(b), naht(c))

Print
Print "5: naht(Anned&(naht(a), naht(b))), naht(Anned&(naht(a), naht(c))), naht(Anned&(naht(b), naht(c))) "
Print naht(Anned&(naht(a), naht(b))), naht(Anned&(naht(a), naht(c))), naht(Anned&(naht(b), naht(c)))

Print: Print "Guten Nacht"

End

Function naht& (x&)
    If x& = 0 Then naht& = -1
End Function

Function Anned& (a&, b&)
    If (a& <> 0) Then
        If b& <> 0 Then
            Anned& = -1
        End If
    End If
End Function

EDIT: naht& bAnd&, Anned&
b = b + ...
Reply
#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
#7
bplus, maybe you should have used nicht instead of naht Smile
Reply
#8
It's my Ohio, USA English? accent ;-))

Probably less confusing if I used Anned& instead of bAnd& also.

"bplus, maybe you should have used nicht instead of naht"
Wait... do you mean "Guten nicht" Smile
b = b + ...
Reply
#9
(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.

Arg, you beat me to it.

Same info, just the geeking out programming version:

   
Reply
#10
First of all thanks for all the tips. I tried a few things today. I was able to reproduce the result with "-16", but there are still a few things that are unclear to me, for example, how Not(20) And Not(40) leads to the correct result: = 61

       1 1 1 1
    + 1 0 1 1
(1)1 0 0 0 0 = -16  (Hope it!)  Rolleyes
Reply




Users browsing this thread: 1 Guest(s)