public static void WriteInt(Stream fs, byte flag, int num)
{
//write the flag (e.g. 0x01, 0xFF, etc.)
fs.WriteByte(flag);
//write the size of the data (Integer = 4bytes)
fs.Write(BitConverter.GetBytes(4), 0, 4);
//write the integer data
fs.Write(BitConverter.GetBytes(num), 0, 4);
}