Valhalla Legends Forums Archive | Battle.net Bot Development | Dword Justification

AuthorMessageTime
NetNX
Are dwords left or right justified? Or does it matter?

What i mean is if i have data that looks like this

00 00 00 0A <- is that a dword

-or-

0A 00 00 00

~_^ started logging other programs then bnet so there was no bnet docs im actually suprised i hadn't run into this problem before
July 14, 2005, 10:20 AM
Ringo
0A 00 00 00 would be 0xA000000 (thats a big number) :P
where as if it were a dword you should retreve it like:
00 00 00 0A
Making it
0xA

Hope that helps
July 14, 2005, 11:13 AM
LoRd
In a little-endian environment, doublewords are read from memory from right to left.
July 14, 2005, 4:13 PM
Newby
For those who don't know (probably quite a few here), x86 is little-endian.
July 14, 2005, 4:31 PM
LivedKrad
[quote author=LoRd[nK] link=topic=12211.msg120689#msg120689 date=1121357580]
In a little-endian environment, doublewords are read from memory from right to left.
[/quote][quote author=Newby link=topic=12211.msg120691#msg120691 date=1121358706]
For those who don't know (probably quite a few here), x86 is little-endian.
[/quote]

Which, as LoRd finally made clear to me, is going to mean the data is going to be read as such: 0x0000000A.
July 14, 2005, 7:17 PM
Myndfyr
[quote author=Ringo link=topic=12211.msg120668#msg120668 date=1121339619]
0A 00 00 00 would be 0xA000000 (thats a big number) :P
where as if it were a dword you should retreve it like:
00 00 00 0A
Making it
0xA

Hope that helps
[/quote]
You have it backwards.

Big-endian 32-bit numbers behave as you indicated.  However, as Newby pointed out, x86 (what most of us work with) is little-endian.  00 00 00 0A would be read as 0x0a000000, a large number.

Endian-ness is the quality of which end (literally) of a number is the most significant.  For ease of understanding, let's work with a 16-bit number:

0x0a0c
0000 1010 0000 1100b (that's the number I gave represented in binary)
^------------------------------ (that's the most significant bit)
In Intel and other little-endian formats, the little end (the least significant byte) comes first:
0000 1100 0000 1010b        0c 0a
In big-endian formats like the Motorola 68000 CPUs, the big end (the most significant byte) comes first:
0000 1010 0000 1100b        0a 0c

We do the same for 32-bit and 64-bit numbers.  Consider the value 0x01020304:
Represented in binary:
0000 0001 0000 0010 0000 0011 0000 0100b
In Little-endian format:
0000 0100 0000 0011 0000 0010 0000 0001b        04 03 02 01

As Wikipedia notes, endianness is an arbitrary distinction, but highly important within-system (so that you follow the convention throughout).

Also, note that endianness does not refer to a sequence of bytes (such as a C-style character array), but only to numeric representations.  However, when you store the constant 'IX86', 'SEXP', or 'WAR3' as a DWORD, we understand why the "string" appears to be reversed.
July 14, 2005, 8:27 PM
NetNX
[quote author=Ringo link=topic=12211.msg120668#msg120668 date=1121339619]
0A 00 00 00 would be 0xA000000 (thats a big number) :P
where as if it were a dword you should retreve it like:
00 00 00 0A
Making it
0xA

Hope that helps
[/quote]

yes thanks very much
July 15, 2005, 5:48 AM
iago
[quote author=NetNX link=topic=12211.msg120837#msg120837 date=1121406503]
[quote author=Ringo link=topic=12211.msg120668#msg120668 date=1121339619]
0A 00 00 00 would be 0xA000000 (thats a big number) :P
where as if it were a dword you should retreve it like:
00 00 00 0A
Making it
0xA

Hope that helps
[/quote]

yes thanks very much
[/quote]

Read MyndFyre's, his is actually right. 
July 15, 2005, 1:22 PM
Ringo
[quote author=iago link=topic=12211.msg120854#msg120854 date=1121433740]
Read MyndFyre's, his is actually right. 
[/quote]
Are you sure, cos i thought it was left.
Who knows :P

July 15, 2005, 1:36 PM
LoRd
[quote author=Ringo link=topic=12211.msg120856#msg120856 date=1121434582]
[quote author=iago link=topic=12211.msg120854#msg120854 date=1121433740]
Read MyndFyre's, his is actually right. 
[/quote]
Are you sure[/quote]

Yes.
July 15, 2005, 4:24 PM
Ringo
So i was wrong?
July 15, 2005, 4:47 PM
Myndfyr
[quote author=Ringo link=topic=12211.msg120878#msg120878 date=1121446032]
So i was wrong?
[/quote]

If we were on big-endian machines, you were right.  Unfortunately, the better majority of us are on little-endian machines.

[quote author=iago link=topic=12211.msg120854#msg120854 date=1121433740]
Read MyndFyre's, his is actually right. 
[/quote]
LoL, thanks iago.  That's the nicest thing you've ever said about me.
July 15, 2005, 5:01 PM
Ringo
I know, i was joking, but i was just useing "0A 00 00 00" as a example of raw data in a packet dump for example.
as nothing more than a 4 byte number, it would represent 0xA000000 in hex, where as if it were a DWORD, it would be obtained as 0xA.

Was just a simple answer to a simple question ;)
July 15, 2005, 5:37 PM
LoRd
[quote author=Ringo link=topic=12211.msg120887#msg120887 date=1121449049]
I know, i was joking, but i was just useing "0A 00 00 00" as a example of raw data in a packet dump for example.
as nothing more than a 4 byte number, it would represent 0xA000000 in hex, where as if it were a DWORD, it would be obtained as 0xA.[/quote]

You don't group raw data and if for some sick, twisted reason you did, 0A 00 00 00 would be read as 0x0000000A since you are infact treating it as a doubleword.  You're hanging yourself.
July 15, 2005, 5:45 PM
Ringo
really? are you sure?

[edit] - reply to lord's edit
It was a Eample of what makes a dword a dword and not just 4 bytes MMKAY? :)
Sorry i didnt over answer the main question!
July 15, 2005, 5:46 PM
LoRd
[quote author=Ringo link=topic=12211.msg120891#msg120891 date=1121449583]
really? are you sure?
[/quote]

No.  It's all part of an evil conspiracy to confuse you.
July 15, 2005, 5:51 PM
Ringo
[quote author=LoRd[nK] link=topic=12211.msg120894#msg120894 date=1121449895]
[quote author=Ringo link=topic=12211.msg120891#msg120891 date=1121449583]
really? are you sure?
[/quote]

No.  It's all part of an evil conspiracy to confuse you.
[/quote]

OMG I KNEW IT!
So.. a dword is reversed?
July 15, 2005, 5:54 PM
UserLoser.
[quote author=Ringo link=topic=12211.msg120896#msg120896 date=1121450095]
[quote author=LoRd[nK] link=topic=12211.msg120894#msg120894 date=1121449895]
[quote author=Ringo link=topic=12211.msg120891#msg120891 date=1121449583]
really? are you sure?
[/quote]

No.  It's all part of an evil conspiracy to confuse you.
[/quote]

OMG I KNEW IT!
So.. a dword is reversed?
[/quote]

No, err ugh, read Myndfyr's post
July 15, 2005, 6:07 PM
Ringo
Confusion conspiracy 1
Ringo 0
:(
July 15, 2005, 6:09 PM
iago
Actually, it goes from outside to in.  So

00 00 00 0A = 0x000A0000
00 00 0A 00 = 0x0A000000
00 0A 00 00 = 0x0000000A
0A 00 00 00 = 0x00BBCCFF

Just to confuse things.
July 15, 2005, 11:06 PM

Search