Can someone explain hex offsets to me?

走远了吗. 提交于 2019-12-18 03:54:45

问题


I downloaded Hex Workshop, and I was told to read a .dbc file.

It should contain 28,315 if you read offset 0x04 and 0x05

I am unsure how to do this? What does 0x04 mean?


回答1:


0x04 is hex for 4 (the 0x is just a common prefix convention for base 16 representation of numbers - since many people think in decimal), and that would be the fourth byte (since they are saying offset, they probably count the first byte as byte 0, so offset 0x04 would be the 5th byte).

I guess they are saying that the 4th and 5th byte together would be 28315, but did they say if this is little-endian or big-endian?

28315 (decimal) is 0x6E9B in hexadecimal notation, probably in the file in order 0x9B 0x6E if it's little-endian.

Note: Little-endian and big-endian refer to the order bytes are written. Humans typical write decimal notation and hexadecimal in a big-endian way, so:

256 would be written as 0x0100 (digits on the left are the biggest scale)

But that takes two bytes and little-endian systems will write the low byte first: 0x00 0x01. Big-endian systems will write the high-byte first: 0x01 0x00.

Typically Intel systems are little-endian and other systems vary.




回答2:


Think of a binary file as a linear array of bytes.

0x04 would be the 5th (in a 0 based array) element in the array, and 0x05 would be the 6th.

The two values in 0x04 and 0x05 can be OR'ed together to create the number 28,315.

Since the value you are reading is 16 bit, you need to bitshift one value over and then OR them together, ie if you were manipulating the file in c#, you would use something like this:

int value = (ByteArray[4] >> 8) | ByteArray[5]);

Hopefully this helps explain how hex addresses work.




回答3:


It's the 4th and the 5th XX code your viewing...

1   2  3  4  5  6
01  AB 11 7B FF 5A

So, the 0x04 and 0x05 is "7B" and "FF".

Assuming what you're saying, in your case 7BFF should be equal to your desired value.

HTH




回答4:


0x04 in hex is 4 in decimal. 0x10 in hex is 16 in decimal. calc.exe can convert between hex and decimal for you.

Offset 4 means 4 bytes from the start of the file. Offset 0 is the first byte in the file.




回答5:


Look at bytes 4 and five they should have the values 0x6E 0x9B (or 0x9B 0x6E) depending on your endianess.




回答6:


Start here. Once you learn how to read hexadecimal values, you'll be in much better shape to actually solve your problem.



来源:https://stackoverflow.com/questions/141262/can-someone-explain-hex-offsets-to-me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!