Skip to content

Instantly share code, notes, and snippets.

@incompl
Created September 20, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incompl/3757491 to your computer and use it in GitHub Desktop.
Save incompl/3757491 to your computer and use it in GitHub Desktop.
// Compact the state.
var slimmerState = new Float64Array([
0,
15.290663048624992,
2.0000000004989023,
-24.90756910131313,
0.32514392007855847,
-0.8798439564294107,
0.32514392007855847,
0.12015604357058937,
1,
7.490254936274141,
2.0000000004989023,
-14.188117316225544,
0,
0.018308020720336753,
0.1830802072033675,
0.9829274917854702
]);
// Impose an 8-bit unsigned format onto the bytes
// stored in the ArrayBuffer.
var ucharView = new Uint8Array( slimmerState.buffer );
var slimmerMsg = String.fromCharCode.apply(
String, [].slice.call( ucharView, 0 )
);
var slimmerMsgSize = getUTF8Size( slimmerMsg ); // 170 bytes
// Decode
var decodeBuffer = new ArrayBuffer( slimmerMsg.length );
var decodeView = new Uint8Array( decodeBuffer );
// Put message back into buffer as 8-bit unsigned.
for ( var i = 0; i < slimmerMsg.length; ++i ) {
decodeView[i] = slimmerMsg.charCodeAt( i );
}
// Interpret the data as JavaScript Numbers
var decodedState = new Float64Array( decodeBuffer );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment