Author Topic: Wiki: "AND" example needs TLC  (Read 2863 times)

0 Members and 1 Guest are viewing this topic.

Offline CharlieJV

  • Newbie
  • Posts: 89
    • View Profile
Wiki: "AND" example needs TLC
« 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

FellippeHeitor

  • Guest
Re: Wiki: "AND" example needs TLC
« Reply #1 on: February 03, 2022, 11:28:20 am »
Looks like you got your wiki account set up. Welcome aboard!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wiki: "AND" example needs TLC
« Reply #2 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.  

Offline CharlieJV

  • Newbie
  • Posts: 89
    • View Profile
Re: Wiki: "AND" example needs TLC
« Reply #3 on: February 03, 2022, 06:47:21 pm »
Fixed:

You beat me to it.  Next one is on me!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Wiki: "AND" example needs TLC
« Reply #4 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.  :-))