 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Zanko Cheater
Reputation: 0
Joined: 28 May 2014 Posts: 40
|
Posted: Wed Jun 15, 2016 6:13 am Post subject: Little and Big endian confusion |
|
|
ADDRESS VALUE(HEX)
0x0 08
0x1 02
0x2 00
0x3 00
If I read 2 bytes with 0x0 as base my end result is (0208)
If I read 4 bytes with 0x0 as base my end result is (00000208)
If I read array of byte of 2 bytes with 0x0 as base my end result is (08,02)
If I read array of byte of 4 bytes with 0x0 as base my end result is (08,02,00,00)
So when I read array of byte should I reverse the array to get my expected result? |
|
| Back to top |
|
 |
cooleko Grandmaster Cheater
Reputation: 11
Joined: 04 May 2016 Posts: 717
|
Posted: Wed Jun 15, 2016 7:43 am Post subject: |
|
|
Computers just always use (LSByte to MSByte). Humans learn the opposite (MSDigit to LSDigit).
When CE displays 2byte and 4byes (aka 16 bit number and 32bit number), it takes the liberty of displaying the hex to you as we would read it.
However, when CE displays an array of bytes, it simply shows you exactly what the array is as it appears in memory.
Since memory is what the computer sees and uses, it will be in (LSByte to MSByte).
Fortunately, when using CE, it always takes care of this for you.
The question for how to help you leaves some confusion. What do you need help with?
Are you reading this from the address list? Lua Script? AA Script?
What do you need: Hex, int, AoB?
In address list, just use w/e format you need and let CE show you the value as you need it.
In LUA, just use readInterger/Float/Bytes
In AA, just use mov/cmp to do what you need.
If you just wanted an explanation for the differences, to put it simply it is all about the difference between a computer and a human and how they have been taught how to read numbers.
Last edited by cooleko on Wed Jun 15, 2016 11:51 am; edited 1 time in total |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4719
|
Posted: Wed Jun 15, 2016 9:28 am Post subject: |
|
|
@cooleko: Your interpretation of endianness is incorrect. The OP was asking about the endianness of bytes, not bits. The term endianness is seldom used to describe the order bits come in. Instead, terms like LSB, MSB, and bit numbering are more common ways of specifying bit order.
Regardless, the term endianness refers to the order the bytes of any singular data object are stored in memory. Little-endian means the least significant bytes come first, while big-endian means the most significant bytes come first.
Most numbers you'll see will be stored in little-endian. As a human, you'll have to manually reverse the byte order if you want to interpret the bytes in memory as a specific type of data. However, when using a computer, it is done automatically for primitive data types. If you're specifying your own custom data type, however, then you may need to take endianness into account (e.g. 8 byte data type in a 32-bit process).
Examples:
| Code: | 4-byte (dec) dword (hex) AoB (little-endian)
1,000,000 000F4240 40 42 0F 00
58,564,720 037DA070 70 A0 7D 03
187,561,656 0B2DF6B8 B8 F6 2D 0B |
Note that x86 assumes multibyte data objects are stored in little-endian. Example:
| Code: | // 01B25000 = 0F
// 01B25001 = 27
// 01B25002 = 00
// 01B25003 = 00
mov eax,[01B25000]
// eax is now 0000270F (9999 in decimal) |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
cooleko Grandmaster Cheater
Reputation: 11
Joined: 04 May 2016 Posts: 717
|
Posted: Wed Jun 15, 2016 10:37 am Post subject: |
|
|
| ParkourPenguin wrote: | | @cooleko: Your interpretation of endianness is incorrect. The OP was asking about the endianness of bytes, not bits. The term endianness is seldom used to describe the order bits come in. Instead, terms like LSB, MSB, and bit numbering are more common ways of specifying bit order. |
Seems a little pedantic when the explanation is about how humans learn their numbering system vs how computers use theirs, humans dont know bits, humans order their values ones, tens, hundreds, in a most significant to least significant fashion.
https://en.wikipedia.org/wiki/Least_significant_bit
| Code: | Least significant byte
LSB can also stand for least significant byte. The meaning is parallel to the above: it is the byte (or octet) in that position of a multi-byte number which has the least potential value. If the abbreviation's meaning least significant byte isn't obvious from context, it should be stated explicitly to avoid confusion with least significant bit. |
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4719
|
Posted: Wed Jun 15, 2016 11:28 am Post subject: |
|
|
Emphasis on "it should be stated explicitly to avoid confusion with least significant bit." The majority of the time I've seen the acronyms LSB/MSB, they were referring to bits; however, that's not remarkably important.
The principal reason I thought you were referring to bits was that you stated computers use big-endian. With regards to bits, this is correct. For example, the byte D6 is 11010110 in binary (and in memory). The most significant bit comes first, while the least significant bit comes last. With regards to bytes, however, this is incorrect. As I explained in my previous post, computers store the bytes in little-endian: the least significant byte comes first, and the most significant byte comes last.
Now that I look back on your post in more detail, it's clear you're confusing big-endian for little-endian. I should have recognized this and been ambiguous when referring to your interpretation of the acronyms LSB and MSB in your explanation. As such, my previous comment wasn't pedantic, but rather flawed in my reasoning of why your explanation is incorrect. Hopefully this post rectifies this situation. _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
cooleko Grandmaster Cheater
Reputation: 11
Joined: 04 May 2016 Posts: 717
|
Posted: Wed Jun 15, 2016 11:52 am Post subject: |
|
|
| Opps, gotcha, My parentheticals were correct but my identification was backwards. Removed the designation to alleviate any potential confusion. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|