QB64 Phoenix Edition
Program Solution#5 - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: Program Solution#5 (/showthread.php?tid=4015)



Program Solution#5 - eoredson - 10-21-2025

Interesting Note:

Code: (Select All)

Rem OOPS here:
f$ = "10": g$ = "1"
If Len(f$) And Len(g$) Then
  Print "Both equal."
End If

Rem OK here:
f$ = "10": g$ = "1"
If f$ <> "" And g$ <> "" Then
  Print "Both equal."
End If



RE: Program Solution#5 - bplus - 10-21-2025

Paradox #5
Code: (Select All)
f$ = "10"
For i = 0 To 9
    g$ = "1" + String$(i, "0")
    Print "f$ = "; Chr$(34); "10"; Chr$(34); " g$ = "; Chr$(34); g$; Chr$(34);
    If Len(f$) And Len(g$) Then
        Print , , " Both equal.";
    End If
    Print
Next



RE: Program Solution#5 - eoredson - 10-21-2025

Since when does:

Code: (Select All)
f$ = "10" g$ = "1"
f$ = "10" g$ = "10"                        Both equal.
f$ = "10" g$ = "100"                       Both equal.
f$ = "10" g$ = "1000"
f$ = "10" g$ = "10000"
f$ = "10" g$ = "100000"                    Both equal.
f$ = "10" g$ = "1000000"                   Both equal.
f$ = "10" g$ = "10000000"
f$ = "10" g$ = "100000000"
f$ = "10" g$ = "1000000000"                Both equal.



RE: Program Solution#5 - bplus - 10-21-2025

Yep that's when!

   


RE: Program Solution#5 - SMcNeill - 10-21-2025

(10-21-2025, 01:34 AM)eoredson Wrote: Since when does:

Code: (Select All)
f$ = "10" g$ = "1"
f$ = "10" g$ = "10"                        Both equal.
f$ = "10" g$ = "100"                       Both equal.
f$ = "10" g$ = "1000"
f$ = "10" g$ = "10000"
f$ = "10" g$ = "100000"                    Both equal.
f$ = "10" g$ = "1000000"                   Both equal.
f$ = "10" g$ = "10000000"
f$ = "10" g$ = "100000000"
f$ = "10" g$ = "1000000000"                Both equal.

N paradox here.   The results are exactly what you programed for.

Code: (Select All)
If Len(f$) And Len(g$) Then
2 AND 1 = 0
2 AND 2 = 2
2 AND 3 = 2
2 AND 4 = 0
2 AND 5 = 0
2 AND 6 = 2
2 AND 7 = 2
2 AND 8 = 0
2 AND 9 = 0
2 AND 10 = 2

AND is used for binary comparison of values. It compares bits. Let's look at 2 AND 3, for example:

00000010 <--- binary for 2
00000011 <--- binary for 3
------------ <-- LET'S AND THEM!!!
00000010 <--- If the bits are both on, keep them if either is off, the result is off.

So 2 AND 3 is 2.

And since 2 is a non-zero value, and zero is the only number we count as FALSE, the result is TRUE.

X AND Y is no where near the same code as X = Y. There's no paradox here. Just bad coding at work, and poor understanding of commands, at work -- which is more or less just part of programming.


RE: Program Solution#5 - bplus - 10-21-2025

See how I set that up for you Steve? Smile

I knew AND was a bit thing but I was guessing it would be every other one that would "be equal" like odd and even numbers or a byte thing... but 2 on then 2 off... more that just one bit then but NOT a whole byte. Its the comparing to len(f$) = 2 then, OK. 


So lets try len(f$) = 7
Code: (Select All)
f$ = "1000000"
For i = 0 To 9
    g$ = "1" + String$(i, "0")
    Print i; "f$ = "; Chr$(34); "10"; Chr$(34); " g$ = "; Chr$(34); g$; Chr$(34);
    If Len(f$) And Len(g$) Then
        Print , , " Both equal.";
    End If
    Print
Next

Calling them " Both equal.", still f's with the mind!  LOL