0

I had trouble using String.fromCharCode in JavaScript(I used it in browser and nodejs), When the parameter was less than 128, I got the same result, but when it was over 128, the result of nodejs was wrong. here is the code and the result in browser:

window.btoa(String.fromCharCode(127))

in nodejs:

Buffer.from(String.fromCharCode(127)).toString('base64')

code & result

so, how can I get the right result with nodejs code?

1
  • 1
    Hi, welcome to stackoverflow. Could you please copy and paste the output rather than posting an image ? It will greatly improve the quality of your question. If you have any question, refer to the how to ask section Commented Nov 20, 2019 at 13:40

1 Answer 1

1

When you do the Buffer.from() call you have to pass "binary" as the second parameter:

Buffer.from(String.fromCharCode(127), "binary").toString('base64')
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.