Encoding VertexData question

Anyone got an example of the opposite of this decoding example

e.g how would you encode the same buffers back the other way. Sorry I am not very good with bit shifting code

var u = 0;
var v = 0;
var height = 0;

function zigZagDecode(value) {
    return (value >> 1) ^ (-(value & 1));
}

for (i = 0; i < vertexCount; ++i) {
    u += zigZagDecode(uBuffer[i]);
    v += zigZagDecode(vBuffer[i]);
    height += zigZagDecode(heightBuffer[i]);

    uBuffer[i] = u;
    vBuffer[i] = v;
    heightBuffer[i] = height; 

}****

I went back through some old posts on this forum and got some good tips so it might be something like below. Let me know if I missed something.

var i;

var prev_u = 0;

var prev_v = 0;

var prev_height = 0;

function zigZagEncode(value) {

return (value << 1) ^ (n >> 31);

}

for (i = 0; i < vertexCount; ++i) {

u = zigZagEncode(uBuffer[i] - prev_u); // get delta and encode

v = zigZagEncode(vBuffer[i] - prev_v);

height = zigZagEncode(heightBuffer[i] - prev_height);

addRow(“vertices”, [uBuffer[i], vBuffer[i], heightBuffer[i]], [u, v, height]);

prev_u = uBuffer[i];

prev_v = vBuffer[i];

prev_height= heightBuffer[i];

uBuffer[i] = u;

vBuffer[i] = v;

heightBuffer[i] = height;

}

I think you’ve got it right. This seems like a good reference and it matches what you have for the encode:

Do you mind linking to the forum threads that helped you figure it out? Might be good for anyone else stumbling on this!

Comments by Kevin Ring helped in this case for what was going on and zigzag encoding I simply googled around.
https://groups.google.com/forum/?hl=en#!searchin/cesium-dev/delta%7Csort:date/cesium-dev/ajm2fgZ1L6c/7xqKGzsjyz0J

https://groups.google.com/forum/?hl=en#!searchin/cesium-dev/delta%7Csort:date/cesium-dev/IpcBEvjt-DA/Y8iF87hQ8R8J