export function float32ToBin(float32: number): string { let str = ""; const c = new Uint8Array(new Float32Array([float32]).buffer, 0, 4); for (const element of Array.from(c).reverse()) { str += element.toString(2).padStart(8, '0'); } return str; } export function float64ToBin(float64: number): string { let str = ""; const c = new Uint8Array(new Float64Array([float64]).buffer, 0, 8); for (const element of Array.from(c).reverse()) { str += element.toString(2).padStart(8, '0'); } return str; } export function convertBinaryIEEE754_32bits_ToNumber(str: string): number { if (str.length !== 32) throw new Error("Binary cannot be converted because the length is not 32.") const arr = []; for (let i = 0; i < str.length; i += 8) { const inner = str.slice(i, i + 8); arr.push(parseInt(inner, 2)); } const c = new Uint8Array(arr); return new DataView(c.buffer, 0, 4).getFloat32(0); } export function convertBinaryIEEE754_64bits_ToNumber(str: string): number { if (str.length !== 64) throw new Error("Binary cannot be converted because the length is not 64.") const arr = []; for (let i = 0; i < str.length; i += 8) { const inner = str.slice(i, i + 8); arr.push(parseInt(inner, 2)); } const c = new Uint8Array(arr); return new DataView(c.buffer, 0, 8).getFloat64(0); }