Convert binary to hex in node.js -
i want ask want convert binary data hex before insert table.
var net = require('net');
var server = net.createserver(function(socket){ socket.on('data',function(data){ var bindata= data.tostring('binary'); //filter(bindata); //if no error convert hex. var hexdata = bindata.tostring('hex'); //insert hexdata here. }); server.listen(3030,'127.0.0.1', function () { console.log("server listenining"); }); but problem binary data inserted.
thank in advance.
parseint("10101001", 2).tostring(16) // => "a9" edit: think misunderstood question. data starts out buffer, convert string, want hex? if so, data.tostring('hex'). if have manipulated bindata, reconstruct buffer:
var bindata = data.tostring('binary'); // bindata var hexdata = new buffer(bindata, 'ascii').tostring('hex');
Comments
Post a Comment