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.

Author
Message
C0wbox
17
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 8th Jan 2011 22:56 Edited at: 8th Jan 2011 23:07
What actually are Dwords and Words? The help files on datatypes don't cover it.



Also, how did I only just notice DBP can do this:

Instead of:

Where were we hiding that kind of programming? - I've been coding in DBP for like 6 or 7 years and never seen boolean statements like that or known DBP can use C++ syntax. xD!


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Jan 2011 23:11
Quote: "The help files on datatypes don't cover it."


From the Help file Datatype section



A word is two bytes, a dword is four bytes or 32 bits.

Quote: "Also, how did I only just notice DBP can do this:"


I've no idea.
C0wbox
17
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 8th Jan 2011 23:18 Edited at: 8th Jan 2011 23:24
Ach, I must have missed it. - I saw a large chunk of blue and thought it was sample code for the integer stuff above.

Thanks.

EDIT:
So basically they're just different sizes of integers yeah? :o (This is what I've never seen help on or had explained.)

Also, why is it I see things like the color backdrop command asking for Dword inputs when for colour? - Does rgb() just return a big number or something?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Jan 2011 23:42
Quote: "Does rgb() just return a big number or something?"


In effect yes. The four bytes are alpha, red, green and blue.

Quote: "So basically they're just different sizes of integers yeah?"


Not really. Integers can be negative. If you examine the ranges for the two types they have the same number of values, just interpreted differently.
C0wbox
17
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 9th Jan 2011 00:02
Oh I see.

What's a word meant to be used for then?



(Also, why are they called Dwords and words? - Where did that kind of notation originate from?)

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Jan 2011 00:58 Edited at: 9th Jan 2011 01:00
The use of "word" in computing goes back a long way. Here's what Wikipedia says:

Quote: "Machine data types

All data in computers based on digital electronics is represented as bits (alternatives 0 and 1) on the lowest level. The smallest addressable unit of data is usually a group of bits called a byte (usually an octet, which is 8 bits). The unit processed by machine code instructions is called a word (as of 2008, typically 32 or 64 bits). Most instructions interpret the word as a binary number, such that a 32-bit word can represent unsigned integer values from 0 to 2^32 − 1 or signed integer values from − 2^31 to 2^31 − 1. Because of two's complement, the machine language and machine don't need to distinguish between these unsigned and signed data types for the most part.

There is a specific set of arithmetic instructions that use a different interpretation of the bits in word as a floating-point number."


That suggests to me that DBPro's use of "word" to mean 16 bits goes back to the days of 16 bit computers. I don't know where it started though.

I expect IanM knows the definitive answer.
C0wbox
17
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 9th Jan 2011 01:18
!

I just thought it was a specifically DBP thing because I mentioned the datatypes Word and Dword in a question to my computing teacher a few years ago now and he didn't have a clue what I was talking about. !

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Jan 2011 12:16
Wrong generation probably.
sladeiw
14
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 9th Jan 2011 13:36
From when I did computer studies (many years back!) I thought a `word` was the maximum amount of data that the cpu could process in 1 go. So a 16 bit processor (Like the Amiga MC68000) with 16 bit registers has a word size of 16 bits. So the architecture of the cpu determined the `word` size. Also I think some systems had limitations reading/writing memory to word boundaries.

I think that byte/word/dword has now just come to mean 8/16/32 bits whatever the architecture, but I'm definitely speaking in `layman` terms! As Green Gandalf said I'll bet IanM can set us all straight.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jan 2011 14:22
I'll have a go then

The definition of WORD goes back a very long way - it's supposed to match the natural register size of the processor (the number of bits it can deal with as a single unit). For instance, I remember reading that the PDP-7 had an 18-bit word size (the machine that Unix was originally written for), others used 12 bits or 36 bits, and some even had variable sized words.

That simple definition became corrupted on the PC with the switch from the 16 bit 8088 processor, to the 32 bit 80286 and above on the PC (for good reason IMO) - a WORD was 16 bits on DOS and 16 bit Windows, and so that existing software could be compiled and run without change (ie for backward compatibility), it was left at that size, despite the processor word size becoming 32 bits.

So now we used DWORD (double word) for 32 bits, and more recently QWORD (quad word) or LONGLONG for 64 bits (don't know what 128-bit or 256-bit quantities are called in Window's terms).

However, these definitions ONLY relate to 32-bit Windows PC's. If you ever compile for different platforms, those definitions do not hold. Whether they do for 64-bit windows or not, I don't know yet, but it would surprise me if they changed drastically.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Jan 2011 15:03
What about the old Commodore/Atari/Spectrum/etc machines from the early '80s? Did they have 8 bit words? If so, what was a byte? Was it a bit smaller? (Sorry. )
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 9th Jan 2011 16:34
I always use DWORDs in types when referring to an object id, is that correct?

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jan 2011 17:07 Edited at: 9th Jan 2011 17:25
Not really - when you use a DWORD, DBPro will convert it into an integer. If you use an integer, that conversion step is avoided. It's not a big speed difference, but over time, it can mount up.

@GG,
On 8-bit machines, I guess that's the case.

For the C programming language, it imposes a structure as follows:
sizeof(byte) <= sizeof(short integer) <= sizeof(integer) <= sizeof(long integer) <= sizeof(long long integer)

... where a straight integer is supposed to be (but does not have to be) the natural word size for the system. I've used the Small-C compiler in the past, and I seem to remember that sizeof(char) = sizeof(short integer) = sizeof(integer), although my memory is a little shaky on that subject.

The actual number of bits involved is not a part of the C specification, which makes life quite difficult when writing portable code, and that's why MS defined all of the upper-case variants of the C types (BYTE, LPSTR, DWORD etc), so that they can be redefined to different types without altering the users source code - WORD could be defined as any integer type with 16 bits (ie it was unsigned integer on 16-bit compilers, but unsigned short on 32-bit compilers).

C has now introduced new types that specify exact number of bits, and at-least number of bits, that makes things a lot simpler: int8_t is an 8-bit integer value (ie, a signed byte or character), uint64_t is an unsigned 64-bit integer, uint_least16_t is an unsigned integer that has at least 16 bits (ie, a WORD).

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2011 12:21
Quote: "C has now introduced new types that specify exact number of bits, and at-least number of bits, that makes things a lot simpler: int8_t is an 8-bit integer value (ie, a signed byte or character), uint64_t is an unsigned 64-bit integer, uint_least16_t is an unsigned integer that has at least 16 bits (ie, a WORD)."


That sounds a lot more logical.

Thanks for the explanations.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Jan 2011 12:44 Edited at: 10th Jan 2011 12:44
Also, everyone probably knows this already, but when you convert a signed type to an unsigned type, or vice-versa, you will never lose any data. -1 when converted to an unsigned type, will be converted to the largest value it can hold. -2 to the second largest, etc.

Also, the only difference internally between a signed and unsigned number is the op-codes used on it. (And in fact, many of those are the same!)

ie. When you multiply/divide two signed numbers together, an IMUL/IDIV instruction will be used, whereas for unsigned numbers, a MUL/DIV instruction will be used. For adding and subtracting, ADD/SUB are used because there is no difference between signed adding and unsigned adding when using "two's complement" to store signed numbers.

[b]
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jan 2011 13:06
Quote: "everyone probably knows this already"


Highly unlikely.

Useful to know thanks.
C0wbox
17
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 10th Jan 2011 17:01
!

So much knowledges.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2011 19:35
So basically you could just say a dword is an unsigned integer (with the addition of an extra bit since its not being used for sign)

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Jan 2011 00:55
Yes, although generally an "unsigned integer" already means with the bit otherwise used for the sign.

[b]

Login to post a reply

Server time is: 2024-04-25 02:35:25
Your offset time is: 2024-04-25 02:35:25