How to get it ID3V2 Total size of tags

Hello everyone, I have a question to ask How do I convert the following code to XOJO

4-byte content

Size=(Size[0]&0x7F)*0x200000 + (Size[1]&0x7F)*0x4000 + (Size[2]&0x7F)*0x80 + (Size[3]&0x7F)

Thank you everyone

Not tested but maybe something like this:

Size = (Size(0) And &h7F) * &h200000 + (Size(1) And &h7F) * &h4000 + (Size(2) And &h7F) * &h80 + (Size(3) And &h7F)

0x7F = &h7f
0x4000 = &h4000
and so on

If Size is a 4 element array, then that should be all you need to convert

If Size is a 32bit integer, you can put it into a memoryblock and then access the individual bytes like this

Dim mb as new memoryblock(4)
mb.UINT32(0) = Size

then use mb.UINT8(0) , mb.UINT8(1) and so on

There may be an issue to do with big and little endian-ness - you might find that the number sequence needs to be reversed, for example.

Sorry, I may not have expressed myself clearly. The original text is as follows:

The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 02 01.

So I found that I should convert it again

So you do not need to 'AND" with 7F hex

It’s mb.uint8(0) * &h200000
plus mb.uint8(1) * &h4000
plus mb.uint8(2) * &h7F
plus mb.uint8(3)

(or 3,2,1,0 possibly.)

I don’t know the principle of the above code, but I still want to thank you. I searched for a feasible method in VB.

//00 00 0A 79 =1401

Var B As BinaryStream
Var D(4) As Double
D(1)=B.ReadUInt8*(2 ^ 21)
D(2)=B.ReadUInt8*(2 ^ 14)
D(3)=B.ReadUInt8*(2 ^ 7)
D(4)=B.ReadUInt8*(2 ^ 0)

MessageBox Str(D(1)+D(2)+D(3)+D(4)) //=1401

:woozy_face:But I encountered a new problem, I don’t know how to write 1401 into a binary file //00 00 0A 79

Use a Binarystream

use WriteInt32 or 4 x WriteInt8
You may need to set the stream to be littleendian = true

Thank you, I used a very clumsy method to achieve it. :grinning_face:

Var S As String=XSize.ToBinary(32)
Var T(4) As String

T(0)="0"+S.Middle(4,7)
T(1)="0"+S.Middle(11,7)
T(2)="0"+S.Middle(18,7)
T(3)="0"+S.Middle(25,7)

Return Integer.FromBinary(T(0)+T(1)+T(2)+T(3))