Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

hex - Explanation on Integer to Array

Please Help

I know that you are reading this, and I would appreciate a comment if do not have an answer because I feel that I am alone in trying to figure this out.

How Does this Work?

I have thoroughly read this document. It mentions an element called TimestampScale. I have downloaded probably thirty WebM example files and seen that the values following the HEX { 0x2AD7B1 or 2A D7 B1 or ['2A','D7','B1'] } or NON-HEX integers { 42 215 177 or [42, 215, 177] } are always the same: HEX { 0x830F4240 or 83 0F 42 40 or ['83', '0F', '42', '40'] } or NON-HEX integers { 131 15 66 64 or [131,15,66,64] }. The values all SHOULD be the default of 1000000 as stated in the Matroska Element Specification. So the question is... How does 0x830F4240 end up as 1000000?

Incase Above Was Too Sloppy For You or You Want More Explanation:

The TimestampScale identifier is equal to 0x2AD7B1. This is in Hexadecimal formatting.

The ways I format it in HEX are:
    0x2AD7B1
    2A D7 B1
    ['2A','D7','B1']

The ways I format it in Integers are:
    42 215 177
    [42, 215, 177]



Its preceding values are taken from a Uint8Array: | 131, 15, 66, 64 |
after the Hexadecimal values are taken. This is NOT in Hexadecimal formatting.
The reason why is because that is the raw data and I want to be
as open with you as possible.

The ways I format it in HEX are:
    0x830F4240
    83 0F 42 40
    ['83','0F','42','40']

The ways I format it in Integers are:
    131 15 66 64
    [131,15,66,64]

So question is: how does | 131, 15, 66, 64 | or 0x830F4240 equal 1000000?

How the all values are shown in HEX and Integers:

    Hex: 2A D7 B1 83 0F 42 40
    Integers: 42 215 177 131 15 66 64

The Goal:

The goal is to figure out how to convert the values to make 1000000, that way I can use this conversion on other elements in the Matroska Element Specification (like duration conversion).

question from:https://stackoverflow.com/questions/65853363/explanation-on-integer-to-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The WebM container format is a subset of the Matroska container format.

Matroska is based on EBML (Extensible Binary Meta Language).

An EBML Document is made of Elements.

An Element is made of an Element ID, an Element Data Size, and Element Data.

An Element Data Size is a Variable-Size Integer. (An Element ID is also a Variable-Size Integer.)

A Variable-Size Integer uses the kind of bit patterns shown below, where the leading bits indicate how many bytes are used and the x bits store the actual value.

  • 1-byte: 1xxxxxxx
  • 2-byte: 01xxxxxx xxxxxxxx
  • 3-byte: 001xxxxx xxxxxxxx xxxxxxxx
  • 4-byte: 0001xxxx xxxxxxxx xxxxxxxx xxxxxxxx

and so on

The TimestampScale Element you mentioned is made of

  • Element ID 2A D7 B1
  • Element Data Size 83 (a 1-byte Variable-Size Integer indicating 3 bytes of Element Data follow)
  • Element Data 0F 42 40 (a big endian encoding of decimal 1000000)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...