fork(1) download
  1. // By Microsoft Copilot
  2.  
  3. function floatToBinary(num) {
  4. const buffer = new ArrayBuffer(8); // 8 bytes for a 64-bit float
  5. const view = new DataView(buffer);
  6. view.setFloat64(0, num); // store the number as a 64-bit float
  7. const binary = Array.from({ length: 8 }, (_, i) =>
  8. view.getUint8(i).toString(2).padStart(8, '0')
  9. ).join(' ');
  10. return binary;
  11. }
  12.  
  13. console.log('Examples of floating-point binary representation:');
  14. console.log(floatToBinary(+1.0));
  15. console.log(floatToBinary(+1.1));
Success #stdin #stdout 0.03s 17184KB
stdin
Standard input is empty
stdout
Examples of floating-point binary representation:
00111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000
00111111 11110001 10011001 10011001 10011001 10011001 10011001 10011010