QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: CharlieJV on February 03, 2022, 10:57:59 am

Title: Wiki: "AND" example needs TLC
Post by: CharlieJV on February 03, 2022, 10:57:59 am
I can't imagine many folk would bother trying that example, but on the off-chance that a programming newcomer did want to learn about AND ...

A little copy/paste typo:

DO
  INPUT "Enter Integer value from -32768 to 32767 (Enter quits): ", INTvalue&
  IF INTvalue& < -32768 OR INTvalue& > 32767 OR INTval& = 0 THEN EXIT DO
  FOR exponent = 15 TO 0 STEP -1
    IF (INTvalue& AND 2 ^ exponent) THEN PRINT "1"; ELSE PRINT "0";
  NEXT
  PRINT " "
 LOOP UNTIL INTvalue& = 0 'zero entry quits
Title: Re: Wiki: "AND" example needs TLC
Post by: FellippeHeitor on February 03, 2022, 11:28:20 am
Looks like you got your wiki account set up. Welcome aboard!
Title: Re: Wiki: "AND" example needs TLC
Post by: bplus on February 03, 2022, 12:24:39 pm
I can't imagine many folk would bother trying that example, but on the off-chance that a programming newcomer did want to learn about AND ...

A little copy/paste typo:

DO
  INPUT "Enter Integer value from -32768 to 32767 (Enter quits): ", INTvalue&
  IF INTvalue& < -32768 OR INTvalue& > 32767 OR INTval& = 0 THEN EXIT DO
  FOR exponent = 15 TO 0 STEP -1
    IF (INTvalue& AND 2 ^ exponent) THEN PRINT "1"; ELSE PRINT "0";
  NEXT
  PRINT " "
 LOOP UNTIL INTvalue& = 0 'zero entry quits


Fixed:
Code: QB64: [Select]
  1.     Input "Enter Integer value from -32768 to 32767 (Enter quits): ", INTvalue&
  2.     If INTvalue& < -32768 Or INTvalue& > 32767 Or INTvalue& = 0 Then Exit Do
  3.     For exponent = 15 To 0 Step -1
  4.         If (INTvalue& And 2 ^ exponent) Then Print "1"; Else Print "0";
  5.     Next
  6.     Print " "
  7. Loop Until INTvalue& = 0 'zero entry quits
  8.  
  9.  
  10.  
Title: Re: Wiki: "AND" example needs TLC
Post by: CharlieJV on February 03, 2022, 06:47:21 pm
Fixed:

You beat me to it.  Next one is on me!
Title: Re: Wiki: "AND" example needs TLC
Post by: bplus on February 03, 2022, 07:08:15 pm
Ha! After I posted it was clear to me, you knew the problem (color coded the err) and you were making another point.  :-))