Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read in a 3 byte size value as an integer in c++?

Tags:

c++

int

byte

id3

I'm reading in an id3 tag where the size of each frame is specified in 3 bytes. How would I be able to utilize this value as an int?

like image 850
carboncomputed Avatar asked Mar 27 '12 19:03

carboncomputed


1 Answers

Read each byte and then put them together into your int:

int id3 = byte0 + (byte1 << 8) + (byte2 << 16);

Make sure to take endianness into account.

like image 76
Carl Norum Avatar answered Sep 27 '22 20:09

Carl Norum