I've got a buffer that
console.log(uid);
// <Buffer 04 23 81 5a 97 37 81>
console.log(uid[0]);
// 4
console.log(uid[1]);
// 35
console.log(uid.toJSON());
// [ 4, 35, 129, 90, 151, 55, 129 ]
console.log(uid.toString());
// #�Z�7�
I need the actual ocelet array (04,23,81,5a,97,37,81) as I need to output
0423815a973781
Any help on figuring out how to parse the buffer in such a manner would be greatly appreciated.
I've got a buffer that
console.log(uid);
// <Buffer 04 23 81 5a 97 37 81>
console.log(uid[0]);
// 4
console.log(uid[1]);
// 35
console.log(uid.toJSON());
// [ 4, 35, 129, 90, 151, 55, 129 ]
console.log(uid.toString());
// #�Z�7�
I need the actual ocelet array (04,23,81,5a,97,37,81) as I need to output
0423815a973781
Any help on figuring out how to parse the buffer in such a manner would be greatly appreciated.
Share Improve this question edited Oct 25, 2014 at 6:05 thefourtheye 240k53 gold badges465 silver badges500 bronze badges asked Oct 25, 2014 at 5:39 CRockCRock 731 gold badge1 silver badge6 bronze badges1 Answer
Reset to default 5The default encoding parameter to Buffer.toString
is utf-8
. That is why you are getting the output like you mentioned in the question.
You just have to decode it with hex
as the second parameter, like this
console.log(Buffer([4, 0x23, 0x81, 0x5a, 0x97, 0x37, 0x81]).toString("hex"));
// 0423815a973781