BBC BASIC for Windows
« IF (....) STATEMENTS »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:55pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: IF (....) STATEMENTS  (Read 549 times)
chrispc
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx IF (....) STATEMENTS
« Thread started on: Jan 27th, 2014, 04:29am »

Richard; thanks for your Sudoku help. I am still looking into the bitmap stuff. However the code you ended with:
IF (num% AND (num%-1)) = 0 THEN just_one_bit_set = TRUE
has me confused. I tried the following uses of that form and got these answers:
1.
A%=0
B%=0
C%=1
D%=2

IF (D% AND C%)=0 THEN
PRINT "YES"
ELSE PRINT "NO"
ENDIF

2.
IF(4 AND 7)<5 THEN
PRINT "YES"
ELSE PRINT "NO"
ENDIF


Then I tried
PRINT (4 AND 7)
and this gave the answer 4, so I thought maybe it was considering only the first-mentioned number. But
3.
IF (7 AND 4)<5 THEN
PRINT "YES"
ELSE PRINT "NO"
ENDIF
also gave the answer "YES".

All the above programs gave the answer "YES". Perhaps you dealt with this in your Tutorial notes but I couldn't find it.
Can you explain please?
Thanks.
chrispc




User IP Logged

ScriptBasic
Guest
xx Re: IF (....) STATEMENTS
« Reply #1 on: Jan 27th, 2014, 08:20am »

Quote:
All the above programs gave the answer "YES".


Your examples (1-3) are printing the correct results.

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: IF (....) STATEMENTS
« Reply #2 on: Jan 27th, 2014, 08:30am »

on Jan 27th, 2014, 04:29am, chrispc wrote:
Can you explain please?

There is a truth-table for the AND operator in the documentation here:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin4.html#and

If you apply that table to the binary values of your numbers everything should become clear. For example in the case of 4 AND 7:

4= 1 0 0
7= 1 1 1
4 AND 7= 1 0 0

So you can see that 4 AND 7 is 4, from which the other results follow.

If you are not familiar with Boolean algebra I would recommend that you spend some time learning about it, since it is so fundamental to programming.

Richard.
User IP Logged

ScriptBasic
Guest
xx Re: IF (....) STATEMENTS
« Reply #3 on: Jan 27th, 2014, 6:00pm »

Based on Chris's response, I get the feeling he thought using the AND would build a macro of values to compare against.

IF(4 AND 7)<5 THEN

What I think Chris expected was the results from this.

IF (4<5) AND (7<5) THEN

Which would print NO for the example.
« Last Edit: Jan 27th, 2014, 6:01pm by ScriptBasic » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls