How are the bytes in a 16bit heightmap organized?

I’m writing a script that reads a heightmap from a binary text file, and programmatically sets said heightmap to the active terrain. To do this for an 8bit heightmap, it’s pretty simple: I just read each byte in the text file, store it in a byte array, translate that into a float matrix, and load the heightmap using terrain.terrainData.SetHeights(0, 0, float) (See code at the end for actual implementation).

This works, but the resolution of the terrain is pretty bad, as the elevations look kind of like stairs. Because of this, I’m going to have to use a 16bit heightmap, but I don’t know how to interpret the bytes from the binary text file, as I don’t know how they’re organized. I’m assuming the corresponding pair of bytes used to represent each elevation value is side by side…?

Here’s the current (working) code for the 8bit heightmap:

using UnityEngine;
using System.Collections;

    public class TerrainGenerate : MonoBehaviour
    {
    	public TextAsset binaryData;
    	
    	private Terrain terrain; // terrain to modify
    	protected int heightmapWidth; // heightmap width
    	protected int heightmapHeight; // heightmap height
    	
    	void Start ()
    	{
    		terrain = Terrain.activeTerrain;
    		heightmapWidth = terrain.terrainData.heightmapWidth;
    		heightmapHeight = terrain.terrainData.heightmapHeight;
    				
    		byte[] bytes = binaryData.bytes; // Loads the whole heightmap file into this array
    		float[,] heightmap = new float[heightmapWidth,heightmapHeight];
    		int byteNumber = 0; // Will be used to iterate through the 'bytes' array
    		for(int width = 0; width < bytes.Length/heightmapHeight; width++)
    		{
    			for(int height = 0; height < bytes.Length/heightmapHeight; height++)
    			{
    				heightmap[width, height] = bytes[byteNumber]/256.0f; // Sets value in 'bytes' array to matrix
    				byteNumber++;
    			}
    		}
    		
    		terrain.terrainData.SetHeights(0, 0, heightmap); // Loads matrix into terrain.
    	}
    }

I’m somewhat unfamiliar with C#, but assuming you can only save byte arrays then you could do the follow, assuming you already have your heightmap stored in an array of integers:

byte[] byteArray = new byte[intArray.length*2];
for(int i=0; i<intArray.length; i+=2)
{
	bytearray _= intArray *& 0xFF;*_

_ bytearray[i+1] = (intArray & 0xFF00) >> 0x08;
}
To get it back into int form you can this:
//Assuming byteArray contains bytes read from serialized data
int[] intArray = new int[byteArray.length/2];
for(int i=0; i<byteArray.length; i+=2)
{
intArray = (byteArray[i+1] << 0x08) | (byteArray*);*
}
Then just transform that int array into your float matrix, should work._

With a 16-bit heightmap, you have 2 bytes for each pixel, organized as either little-endian (where the least significant byte is first) or big-endian (where the most significant byte is first). There’s no way to know which is used in the file, so it would be best to support both.

Bit late to the party.
Converting byte arrays ( binary data ) into other simple types (ushorts etc )in c# use System.BitConverter. New to unity though not c# so I’m presume this is available. It has functionality to help with architecture endian also.