我正在tcp套接字上接收000F313233343536373839393303132333435作为字节,并希望将其转换为123456789012345我希望将套接字上接收的此字节流解析为数字。
function onConnect(socket) {
socket.setEncoding('utf8');//Socket data to utf8 format
socket.on('data', function (data) { //Socket event when data is sent from tcp client
var buffer = Buffer.from(data,"hex");
let clientport=socket.remotePort;
let clientadd=socket.remoteAddress;
console.log(clientadd+":"+clientport)
console.log("--",data,"--")
console.log(buffer);
var msg = buffer.toString()
var msglength = msg.length;
console.log(msglength);
})//<=on data
1条答案
按热度按时间d7v8vwbk1#
如果你知道你的号码永远适合你
Number.MAX_SAFE_INTEGER
你可以使用简单的Number
转换:或是
BigInt
如果可以是任意长度的整数:stackblitz链接