You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@nlapshin To expand a bit on the answer here – the issue is that there’s no way to tell which byte(s) you mean by the hex string 5. It could be 0x05, or 0x50, or something else. Similarly, your example won’t work on numbers that lead to other odd hex string lengths – e.g. Buffer.from('abc', 'hex') will lose the c, because it doesn’t know what to do with it.
If you need a way to convert numbers into Buffers, maybe consider using the Buffer.writeInt* methods.
@nlapshin To expand a bit on the answer here – the issue is that there’s no way to tell which byte(s) you mean by the hex string 5. It could be 0x05, or 0x50, or something else. Similarly, your example won’t work on numbers that lead to other odd hex string lengths – e.g. Buffer.from('abc', 'hex') will lose the c, because it doesn’t know what to do with it.
If you need a way to convert numbers into Buffers, maybe consider using the Buffer.writeInt* methods.
Oh, thanks for the detailed response. I understood that hex string '5' or 'b' is one byte. And now, I understand, after your explantation, why 'Buffer.from' works that way.
@nlapshin To expand a bit on the answer here – the issue is that there’s no way to tell which byte(s) you mean by the hex string 5. It could be 0x05, or 0x50, or something else. Similarly, your example won’t work on numbers that lead to other odd hex string lengths – e.g. Buffer.from('abc', 'hex') will lose the c, because it doesn’t know what to do with it.
If you need a way to convert numbers into Buffers, maybe consider using the Buffer.writeInt* methods.
If you have any more questions about this, https://github.com/nodejs/help might be a good place.
Oh, thanks for the detailed response. I understood that hex string '5' or 'b' is one byte. And now, I understand, after your explantation, why 'Buffer.from' works that way.
Activity
seishun commentedon Nov 19, 2018
Works as expected. 'hex' encodes one byte as two hex characters - one character is not a valid hex string.
addaleax commentedon Nov 19, 2018
@nlapshin To expand a bit on the answer here – the issue is that there’s no way to tell which byte(s) you mean by the hex string
5. It could be0x05, or0x50, or something else. Similarly, your example won’t work on numbers that lead to other odd hex string lengths – e.g.Buffer.from('abc', 'hex')will lose thec, because it doesn’t know what to do with it.If you need a way to convert numbers into
Buffers, maybe consider using theBuffer.writeInt*methods.If you have any more questions about this, https://github.com/nodejs/help might be a good place.
nlapshin commentedon Nov 20, 2018
Oh, thanks for the detailed response. I understood that hex string '5' or 'b' is one byte. And now, I understand, after your explantation, why 'Buffer.from' works that way.
Thanks a lot!
doc: explain `hex` encoding in Buffer API
doc: explain `hex` encoding in Buffer API
doc: explain `hex` encoding in Buffer API
doc: explain `hex` encoding in Buffer API
hazae41 commentedon Jan 19, 2023
Days since last bug caused by this: 0
Trott commentedon Jan 19, 2023
@nodejs/buffer Is there any support for a breaking change that throws rather than discards data in this situation?
Trott commentedon Jan 19, 2023
And if not, how about a warning?
jasnell commentedon Jan 19, 2023
I'd be happy with a throw but we'd have to take the current behavior through a deprecation cycle first
damien876 commentedon Oct 17, 2025
https://jquery-paginationinitial.github.io/AvIVlOj4qK/