Why do you have to convert strings to DWords? And, what does the string "look" like when it's in memory as a DWord? Also, does the length of the string affect the conversion? For example if I had a string like this: "This is a string which has more bytes than a DWord?!".
As you can see I've got myself very confused, some simple explanation would be great.
Thanks a lot,
Posted on 2002-09-10 05:05:54 by adamjjackson

STRING and NUMERIC data are just different formats, computers arbitrarily nominate characters as numbers so they can be worked with but those numbers do not translate to doing arithmetic operations.

You cannot add the two strings "ONE" and "TWO" or the strings "1" and "2" together because the individual character numbers are identifiers for the characters, not numeric values.

Different hardware has different ways of storing proper numbers, x86 processors store the numbers in memory in reverse, many others like 68k processors store numeric data the other way around so the actual method of data storage is hardware determined.

The basics of your question is what values you need to work with, string values have their place for many different things, numeric values also have their place, it just depends what you need and when you need to, you can convert between the two.


Posted on 2002-09-10 05:13:55 by hutch--
Who converts strings to dword?
I usually place strings in my code like this:
String1 DB "This is a string",0
This means I declare a new variable of BYTE type and place the string characters one after another in memory beginning at the address of this variable. The string is stored like this:
String1[1]='h'.. and so on.
If a declared it as DWORD - String1 DW "This is a string",0 - It would be a DWORD variable and placed in memory like this:
String[1]=' ','s','i',' '..and so on
This type of storage is called 'little endian' as i recall, which means the lower byte is stored first the highest last.
When you call any function, that needs to display a string, say, MessageBox, you don't give it your string as a parameter, you must specify the address of your string, e.g.
invoke MessageBox NULL, OFFSET String1, OFFSET String2, MB_OK
Address takes 4 bytes (DWORD), but the string is not converted to DWORD.
Hope this helps...
Posted on 2002-09-10 05:27:40 by Vaxon
I get that, but I don't understand how converting a long string to a DWord works, is it just that the numeric representation of each character is changed from a byte to a DWord?
Posted on 2002-09-10 05:29:04 by adamjjackson
Sorry, I'll try to clarify why I asked the question. For example in a List view control when comparing strings for the purpose of ordering they are converted to a DWord, I was wondering why, and what exactly it meant...
Posted on 2002-09-10 05:31:37 by adamjjackson
That procedure is used to convert string, containing a numer into that number. You can't use it for any string you like. If you want to compare 2 numers stored as strings, you must convert them to numbers, because you can't compare strings.
String1 DB "65534" takes 5 bytes of memory: 54, 53, 53, 51, 52 (36h, 35h, 35h, 33h, 34h) - these numbers are ASCII codes for symbols '6','5','5','3','4'.
converting it to a dword numer you get 65534 (0000FFFEh) number which takes 4 bytes of memory like this:
254, 255, 0, 0 (FEh, FFh, 00h, 00h)
Numbers in brackets() are hexadecimal.
Posted on 2002-09-10 05:57:16 by Vaxon
There is no such type as a "long string".

A string is a sequence of characters. The characters are stored as 8-bit bytes. And the bytes can be interpreted as numbers or as characters. ASCII is just one set of interpretations of 8-bit (actually 7-bit) values as characters. EBCDIC (used on mainframes) is another.

There is such a thing as a "wide string" (a C/C++ term). The characters are stored as 16-bit values. These 16-bit values can be interpreted as numbers or as characters. Unicode is just one set of interpretations of 16-bit values as characters. I believe Xerox PARC created another for their Smalltalk systems.

A DWORD is a 32-bit value. This value can be presented as a binary number, a hexadecimal number, or a decimal number.

String comparisons create a lexical (almost alphabetical) ordering.
If you don't convert numeric strings to their equivalent numeric values, you can get this ordering:


when you wanted


Notice that the first ordering is basically alphabetical ordering:

Posted on 2002-09-10 18:24:16 by tenkey
Think of it as two different types of strings.

The first being alphabetical strings like "This is a string". These are usually "moved around" as is, and are often terminated by the NULL character.

The second is a numeric string like "1234567". These could also be terminated by a NULL, or they could be an assumed length, depending on the application.

You need to convert the numeric string to binary (word, dword, qword) pretty much any time you want to do math or compare operations.

You'll also need to convert a binary result back to a string whenever you need it to be "people readable".

Posted on 2002-09-10 21:03:42 by S/390
Just a quick note to thank you guys, that helped a lot.
Cheers again,
Posted on 2002-09-12 03:49:17 by adamjjackson