I’m trying to pattern match a binary file where the second value is a float. For example:
<< "JPEG", version :: size(5), rest :: binary >>
The version should be something like
All I’m getting back though is version =
Is there a special way to match on float values?
March 24, 2017, 5:19pm
That’s not a float. They usually have a size of 32, 64 or 128 bit, not 5. I do think that you really want to have 5 bytes instead of bits and then just handle them as a string.
I think you’re right. The spec says the version is five characters, and the example is 01.50
March 24, 2017, 6:04pm
The term characters is a very strong hint for a string type.
That’s what I thought when I first read it, but then the rest of the spec continues to use characters even when they’re just digits. That was only the second term in the spec, so I’m guessing everything is a string based off that.
March 24, 2017, 6:11pm
The word digit means a number from 0 to 9, which is most of the time encoded in of three ways.
a byte that just represents the digit. Wasting much space of the byte
a half byte, this way you can encode two digits into a single byte
the ASCII representation of the digit. While wasting space again this is easily inspectable with a lot of tools.
So unless specified as integer or float including it’s width and endianness, it’s almost everytime just characters.
I’ve got another question, but I’m going to ask it in another thread. Perhaps if someone can answer, it may help other people.