3

I have a buffer in this format:

<Buffer 24 b0 5e 65 3f 26 74 4e 9a ba 87 35 2d 83 cd 54 17 09 9b 1b cc 72 58 16 99 6d d6 5c b7 fa b6 63>

And I need to convert it to hex format:

24b05e653f26744e9aba87352d83cd5417099b1bcc725816996dd65cb7fab663

All the examples I see do it like this, but it has no effect when I try it.

b=getBuffer(data);
console.log(b);
hex=Buffer.from(b, 'hex')
console.log(hex);

OUTPUT:

<Buffer 24 b0 5e 65 3f 26 74 4e 9a ba 87 35 2d 83 cd 54 17 09 9b 1b cc 72 58 16 99 6d d6 5c b7 fa b6 63>
<Buffer 24 b0 5e 65 3f 26 74 4e 9a ba 87 35 2d 83 cd 54 17 09 9b 1b cc 72 58 16 99 6d d6 5c b7 fa b6 63>

Any ideas? Thanks in advance.

3
  • There's no apparent relationship between the "buffer" and the desired output. Commented Mar 11, 2018 at 13:56
  • You are correct. Since I cant convert it to hex I provided a sample (unrelated) value in the desired format. Commented Mar 11, 2018 at 14:01
  • Does this answer your question? How to display nodejs raw Buffer data as Hex string Commented Jan 26, 2024 at 22:25

2 Answers 2

8

This should convert your buffer to hex:

b.toString('hex');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. I see now the buffer was already in hex and converting it to string is just concatenating all the values... jokes on me I guess.
0

For whoever getting the warning Invalid number of arguments, expected 0 with the solution proposed by @TwistedOwl, here a solution to get rid of the warning:

Buffer.from(b).toString('hex');

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.