Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
11-16-2022, 09:52 PM
(This post was last modified: 11-16-2022, 10:00 PM by Kernelpanic.)
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
Posts: 1,510
Threads: 53
Joined: Jul 2022
Reputation:
47
Where is "(not a) and (not c)"? How about involving "c" and "d" only? You have to complete the test suite...
Posts: 336
Threads: 24
Joined: Apr 2022
Reputation:
19
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;
}
Posts: 241
Threads: 10
Joined: Apr 2022
Reputation:
30
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.
Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
11-16-2022, 11:36 PM
(This post was last modified: 11-16-2022, 11:49 PM by bplus.)
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 + ...
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
(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.
Posts: 336
Threads: 24
Joined: Apr 2022
Reputation:
19
bplus, maybe you should have used nicht instead of naht
Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
11-16-2022, 11:43 PM
(This post was last modified: 11-16-2022, 11:54 PM by bplus.)
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"
b = b + ...
Posts: 490
Threads: 95
Joined: Apr 2022
Reputation:
23
(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:
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
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!)
|