I'm writing raw byte values to a file:
- When values are <= 127, everything is ok.
- But if a byte is > 127, it gets all messsed up.
I've already tried changing encoding format and such, with no success.
public static void Generate()
{
var fileName = "Test.bin";
if (File.Exists(fileName))
File.Delete(fileName);
using (var binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
var byteArray = new byte[] {0x01, 0x02, 0x7F, 0x80};
foreach (var b in byteArray)
{
binaryWriter.Write(b);
}
}
}
On the above code, the resulting file should be:
01 02 7F 80
But what I get is:
01 02 7F D0 90
Any clue on whats happening?
Here's a test application: http://pastebin.com/0Cfv3Snc
Here's the generated files: http://postimg.org/image/55un9lar1/
I doesn't work on any of my two PCs. Running .NET 4.0 on Windows 10.