netkitty
Version:
Network tools kit
27 lines (26 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Float32ToHex = exports.UInt64ToHex = exports.UInt32ToHex = exports.UInt16ToHex = exports.UInt8ToHex = exports.Int64ToHex = exports.Int32ToHex = exports.Int16ToHex = exports.Int8ToHex = void 0;
const Int8ToHex = (value) => new Uint8Array(Int8Array.from([value]).buffer)[0].toString(16).padStart(2, '0');
exports.Int8ToHex = Int8ToHex;
const Int16ToHex = (value) => new Uint16Array(Int16Array.from([value]).buffer)[0].toString(16).padStart(4, '0');
exports.Int16ToHex = Int16ToHex;
const Int32ToHex = (value) => new Uint32Array(Int32Array.from([value]).buffer)[0].toString(16).padStart(8, '0');
exports.Int32ToHex = Int32ToHex;
const Int64ToHex = (value) => BigInt(value).toString(16).padStart(16, '0');
exports.Int64ToHex = Int64ToHex;
const UInt8ToHex = (value) => value.toString(16).padStart(2, '0');
exports.UInt8ToHex = UInt8ToHex;
const UInt16ToHex = (value) => value.toString(16).padStart(4, '0');
exports.UInt16ToHex = UInt16ToHex;
const UInt32ToHex = (value) => value.toString(16).padStart(8, '0');
exports.UInt32ToHex = UInt32ToHex;
const UInt64ToHex = (value) => BigInt(value).toString(16).padStart(16, '0');
exports.UInt64ToHex = UInt64ToHex;
const Float32ToHex = (value) => {
const buffer = new ArrayBuffer(4);
const dataView = new DataView(buffer);
dataView.setFloat32(0, value, false);
return dataView.getUint32(0, false).toString(16).padStart(8, '0');
};
exports.Float32ToHex = Float32ToHex;