Created
December 1, 2017 21:39
-
-
Save raypulver/9bbcc4fd768d95aa070b4c406f220c13 to your computer and use it in GitHub Desktop.
show me that double
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const number = 100; | |
// see the actual bits, since JS uses 64-bit doubles | |
let buffer = new ArrayBuffer(8); | |
let doubleLoader = new Float64Array(buffer); | |
doubleLoader[0] = number; | |
let bytes = new Uint8Array(buffer); | |
// output the bytes | |
console.log([].slice.call(bytes)); | |
// give me pad left or give me death | |
const padLeft = (s, char, len) => s.length >= len ? s : Array(len - s.length + 1).join(char) + s; | |
// output the bits | |
console.log([].map.call(bytes, (v) => padLeft(v.toString(2), '0', 8)).join('')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment