public static void WriteShort(Stream fs, byte flag, short val)
{
//write the flag (e.g. 0x01, 0xFF, etc.)
fs.WriteByte(flag);
//write the size of the data (Long = 2bytes)
fs.Write(BitConverter.GetBytes(2), 0, 4);
// write the integer data
fs.Write(BitConverter.GetBytes(val), 0, 2);
}