fork download
  1. // By Microsoft Copilot
  2.  
  3. function floatToHexadecimal(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 hexadecimal = Array.from({ length: 8 }, (_, i) =>
  8. view.getUint8(i).toString(16).padStart(2, '0')
  9. ).join(' ');
  10. return hexadecimal;
  11. }
  12.  
  13. console.log('Examples of floating-point hexadecimal representation:');
  14. console.log(floatToHexadecimal(+1.0));
  15. console.log(floatToHexadecimal(+1.1));
Success #stdin #stdout 0.04s 16908KB
stdin
Standard input is empty
stdout
Examples of floating-point hexadecimal representation:
3f f0 00 00 00 00 00 00
3f f1 99 99 99 99 99 9a