Fastest way to convert a integer to arbitrarily ordered byte arrays in JavaScript?
问题 I'm looking to convert the MIN_SAFE_INTEGER through MAX_SAFE_INTEGER range of a JavaScript number (53-bits not including the sign) into a string of bits spread over 7 bytes shifted two to allow for sign and null identifiers. Thus far the best I've come up with is: function toUint8Array(data) { data = data.toString(2); data = new Array(65 - data.length).join('0') + data; var ret = new Uint8Array(data.length / 8); for (var i = 0; i < 8; i++) { ret[i] = 0; ret[i] += (data[i * 8] == '1' ? 128 : 0