Explanation on Integer to Array

家住魔仙堡 提交于 2021-02-08 08:40:22

问题


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).


回答1:


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)


来源:https://stackoverflow.com/questions/65853363/explanation-on-integer-to-array

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