If your value is 258, then it won't fit in a byte anyway - a byte is eight bits, and can hold numbers between 127 and -128, or 0 - 255 if it is unsigned.
If your
value
is a 32 bit integer as your code implies, then it will always require 4 bytes in your output file - otherwise you cannot store the full range of numbers that the variable
value
can hold.
Try writing it to the file as a array of bytes - it makes things a lot easier!
int value = -12345678;
byte[] bytes = BitConverter.GetBytes(value);
int rebuilt = BitConverter.ToInt32(bytes, 0);
bytes
will hold four bytes:
Decimal: 178 158 067 255
Hex: B2 9E 43 FF
Which is the binary equivalent of -12345678 (Little endian notation, which is normal for .NET and PC's generally)