Code-Miesters.
Is anyone here good at binary?
I am freading from a binary file as follows
$var = Hex2Dec(Bin2Hex(strrev(fread($fp, 4))))
and modifying $var, then I want to put the data back into the source file in the format in which I took it out, but its not working.
The source file is 8-bit, unsigned little-endian.
When I attempt the inverse of the nested functions that convert the data, what goes back in is wrong.
Explanation:
If I fread() and display from the source file with no conversion, I get gobbledegook in between an occasional readable chunk title.
If I fread() what I put back in, I get the same readable chunk titles but in between them are very clear 1's and 0's, and of course the files are unusable/unrecognised by the software meant to use them.
I'm converting in a way that seems to what makes sense, there just seems to be two kind of binary - human-readable strings("1101") and unreadable gobbledegook. I want the unreadable gobbledegook 🙁
When putting 4 bytes of supposed binary back into the source, what its putting back is way more than 4 bytes, "1101" is apparently 4 bytes.
4 bytes should be more like 11011110 01100101 11100011 10001100.
I'm sure I'm missing something here. Any help would be appreciated.
Stumped,
Bah