user2366975
user2366975

Reputation: 4710

Why is known what is a byte in a bytestream?

If I have a wav-file, and its header starts this way:

5249 4646

Then, if I read it in somehow like (stream is a QByteStream)

char riff[4] // 4 byte
stream.readRawData(riff,4); // reads 4 bytes into the char riff

Why is known that 4 bytes mean 5249 4646? One byte 52, the next 49, and so on. If it was a text .txt-file, every single visible character would be a byte, not every two. What we see, is it the same the stream is seing?

Upvotes: 1

Views: 504

Answers (2)

David Heffernan
David Heffernan

Reputation: 613382

5249 4646

is actually 4 bytes expressed as hex. You might write them like this:

52 49 46 46

which is more byte oriented.

Now, ASCII code for R is 0x52. For I it is 0x49. And for F it is 0x46.

The specification for these files mandates that the first 4 bytes of the file is the header, and that header must be the 4 bytes that we have picked apart above. A good reason for picking these 4 bytes is that when you look at the file in a hex editor, the hex editor will attempt to interpret the bytes as ASCII if it can and so you can see by simple inspection that the first 4 bytes interpreted as ASCII are RIFF and then you know, in all likelihood, what kind of file it is.

For example, here's a sample WAV file as viewed in a hex editor:

enter image description here

Upvotes: 4

Reticulated Spline
Reticulated Spline

Reputation: 2012

Those 4 bytes are not known. You're just reading 4 bytes, that's it. A single byte has a value between 0 and 255.

Upvotes: 0

Related Questions