Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Boolean and Binary?

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2007 19:36
Is there any way to use boolean and binary numbers in DBC?

In programming, nothing exists
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 27th Sep 2007 19:37
I know you can use booleans, as far as binary I can't help ya there mate.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2007 19:38
how do you use boolean?

In programming, nothing exists
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Sep 2007 19:44 Edited at: 27th Sep 2007 19:45
There are no specific boolean variables in DBC, but you can do what I do - create two variables at the start of your program called True and False:

True=1: False=0

In your program, you can set the value of other variables with:

ReachedTheGate = True

This then allows you to use:

If ReachedTheGate = True Then Gosub ShowWizard

... or whatever.

As for Binary, you have to code it manually as bit access isn't natively supported in DBC.

You can convert a decimal integer to a binary string with Bin$(), but you'll have to write your own functions to use the result or convert it back to decimal again (not too difficult).

TDK_Man

Binary Coder
18
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 6th Oct 2007 08:18 Edited at: 6th Oct 2007 08:19
Something like this...



Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Oct 2007 23:36
What exactly did you need binary numbers for?


Binary Coder
18
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 7th Oct 2007 09:20
Wondering the same thing...

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2007 00:20
I can't actually remember
I think it was something to do with independent switches.
if I used 1 2 4 8 as separate switches I could check which were being pressed even when more than one was pressed ie
input 7 = 1+2+4

liking the banner BC

In programming, nothing exists
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Oct 2007 06:19 Edited at: 9th Oct 2007 16:46
32 switches:

2^0 - 2^31

Set whatever variables you want that identify the switches:

up=2^0
down=2^1
left=2^3
right=2^4
etc.

Have an integer variable that would store the switches:
switchstate=0

Through code or keys being pressed, turn on the available switches:
if upkey()=1 then switchstate=switchstate | up

Check the variable to see which switches are active:
if switchstate & up = up then do something

When you want all of the switches off set the individual switches to 0 or the whole variable:
switchstate=0
or possibly
switchstate=switchstate-up (this should work for individual switches since they are binary and each value is a bit value)

Enjoy your day.
Binary Coder
18
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 9th Oct 2007 13:34 Edited at: 10th Oct 2007 13:38
[Edit]

Comrade Robski
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 9th Oct 2007 17:44
@TDK and OBese87

I believe (although I don't have DBC in front of me) that the following will work as a simplified version of TDK's code:

If ReachedTheGate then .... else ....

with no need to explicitely specify the '= True' part. The condition will be true if ReachedTheGate=1 (or perhaps if ReachedTheGate =/= 0) and false if ReachedTheGate=0.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2007 18:06 Edited at: 9th Oct 2007 18:08
@CR
That is true but the variable is taking up more memory than a boolean number would. And yes you're right, you don't need to specify the "=" DB will assume you are checking for TRUE(=1) unless told otherwise.
I am disappointed with the lack of logic operators in DB there's only AND and OR isn't there?
otherwise you could have things like: if NOT reachedthegate then ...
but in this situation it doesn't give much benefit.
I would like to see all of them
AND - both true (11)
OR - at least one true (10 OR 01 OR 11)
NOT - false (0)
XOR - only one true (10 OR 01)
is that right? I think there's another one too.
[edit]
NAND - both false (00)
any more?

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 9th Oct 2007 18:08
NOR (not or) and NAND (not and) exist as well.



Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2007 18:10 Edited at: 9th Oct 2007 18:10
haha INH you beat me to it
what's NOR do? Is it:
NOR - both true or false (11 or 00) (not or)

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 9th Oct 2007 18:13
I haven't go a clue... I think it's at least one NOT true, i.e the opposite of or.



Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2007 18:32
no that's XOR

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 9th Oct 2007 19:05
No, becuase XOR only allows 10 OR 01. NOR would allow 10,01 and 00 but not 11.



Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2007 23:47
oh right i get you

In programming, nothing exists

Login to post a reply

Server time is: 2025-05-31 20:42:31
Your offset time is: 2025-05-31 20:42:31