6

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.

1 Answer 1

5

The 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.