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 Professional Discussion / how many bit should boolean have?

Author
Message
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 22nd Jul 2010 14:50
was hoping to use boolean as a checker but it only has 8 bits, is this right.

some code to show what I mean, loaded with nine bits but is only show 8, unless its and integer.



Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Jul 2010 15:05
If you need up to 8 bits, use a boolean or byte.
If you need up to 16 bits, use a word.
If you need up to 32 bits, use a dword or integer.
If you need up to 64 bits, use a double integer.

Technically, there's no need for the boolean type, as it acts exactly like a byte in all cases using vanilla DBPro, but I have used it in my file and bank plug-ins to force either a 0/1 value to be written/read.

Globbits
17
Years of Service
User Offline
Joined: 30th Jan 2009
Location: Cambridge
Posted: 22nd Jul 2010 15:06
That's odd. As far as I understood it a boolean should only have one bit (0 or 1). A byte should have 8 bits (0 to 255).
As DBPro has both datatypes I would have thought that this is true, but is seems not to be the case, e.g.

This shouldn't work, right?
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 22nd Jul 2010 15:16
shoot, thought I had use the wrong word, should have been bytes, Ho well learnt a bit more, or is it byte more,

Dark Physics makes any hot drink go cold.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 15:41
@Globbits
Booleans and bytes are almost identical in DBPro. You can't address anything smaller than a byte.

[b]
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jul 2010 15:42
The boolean type in DBPro probably just uses bytes, because it would be slower to convert back and forth, and with videogames, there's just no huge demand for exacting data types.
Even though internally, the executable will use binary all over the place, the nature of DBPro means that it would be slower to use real binary than just using a byte.

Really, bytes are the only memory variable type, they represent characters, 2 bytes represent a word, 4 a dword or integer as Ian already said - but everything is stored as bytes no matter how you look at it. Integers, strings, floats, and anything that is bigger than a byte, is made from bytes, so in my book, it's bytes. It helps if you learn this stuff yourself, using hex editors in the 80's . Even when a file is in an established base, like email files tend to be stored in Base6 I think, but this base6 data is still stored as bytes. Often people might assume that they'd use Base6 for the sake of transfer speed - it's more about file integrity, adding checksums for instance. When you send an email, it gets converted to base6 and bloats by about 1/3rd! - that's why you can't always trust file size limits, because they don't always allow for the bloat.

So after that windbag paragraph, I guess I'm saying your as well just using bytes and forgetting boolean as far as DBPro is concerned.


Health, Ammo, and bacon and eggs!
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 15:46 Edited at: 22nd Jul 2010 15:46
However using booleans makes the code more readable, as even if more values are allowed, the reader of the code knows that only 1 or 0 is intended.

Even in the C/C++ specification, there are no restrictions on the amount of memory used for any particular data type, except that a long long must be at least as big as a long, which must be at least as big as an int, which must be at least as big as a short, which must be at least as big as a char, which must be at least as big as a bool.

[b]
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jul 2010 17:27
Definitely, there's a lot to be said for adding your own True and False constants. It is a shame that DBPro is not just a little more efficient with binary, because I'd use it all the time. Setting a load of flags for SET OBJECT for instance, those are all bool's, so they could conceivibly be set by passing a single byte value, made up from the bit 'flags'. SET OBJECT 10,184... that would be cool, really easy standardised object setup, using a simple integer value.
I think that it is how it is, because most people using DBPro are self-taught, and binary is one of those concepts that might seem like pointless obfuscation. It would be bloody awesome if we could specify bit types, like a list of bool properties, and have them stored as an integer for easy copying, setting, file storage.


Health, Ammo, and bacon and eggs!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Jul 2010 19:36 Edited at: 22nd Jul 2010 19:37
Quote: "Booleans and bytes are almost identical in DBPro. You can't address anything smaller than a byte."


That's why I never use BOOLEAN in UDTs since a BYTE and a BOOLEAN save in a file the same. Plus if I eventually need something a bit more than just an on/off switch if it's set as a byte already I have 255 different toggles I can use.

Login to post a reply

Server time is: 2026-07-25 05:32:39
Your offset time is: 2026-07-25 05:32:39