M
M
Muranx2020-08-23 16:22:12
Node.js
Muranx, 2020-08-23 16:22:12

How does buffer in node.js translate the '#' character?

Hello!

let buff = Buffer.from('A');

console.log('A'.charCodeAt( 0 )); // 65
console.log(buff); // <Buffer 41>
console.log(buff.length); // 1

In this case, everything seems to be clear, we create a buffer, we pass the letter "A" into it, its code from the encoding table is 65, in the hexadecimal number system it turns out 41 (as far as I know, 16tyric s.s. is used for display), well, when transferring this letter "A", let's say when reading a file or writing, in fact, a code is transmitted in binary s.s., which (if the converter does not change me) is equal to " 1000001 ".
Question 1 : Have I correctly described what is happening above?
Question 2 : 41 is the binary representation of a byte (sorry for the clumsy interpretation), which is supposed to be 8 bits right? Those. if 41(16tyric.) === 1000001(2ch.) , then there are not enough bits, and they are appended to the beginning, i.e. when transmitted, it will be 01000001, i.e. +1 zero (0) at the beginning ?
let buff = Buffer.from('№');
console.log('№'.charCodeAt( 0 )); // 8470
console.log(buff); // <Buffer e2 84 96>
console.log(buff.length); // 3

It's generally dark here, how are these "octets" filled in, are they counted separately? Those. If you translate it manually, it will look like this ?. . .
e2(16тирич.) === 11100010
84(16тирич.) === 10000100
96(16тирич.) === 10010110
Or not? Please either explain what my mistakes are, or where I am still right, or answer questions with explanations, because faced such a problem that everyone explains everywhere that there are bytes in the buffer, and they store character codes, and give a couple of thawed examples with some string "hello", that they say that each byte is a binary representation of a letter, mu, but how is it no one mentions the translation, or I just didn’t find it, for the first time in my life I would even be pleased with a quality link to an article in which this ins and outs would be painted, because I don't even know what to look for, what is the name of this translation process in the context of an object buffer! Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-08-23
@Muranx

https://ru.wikipedia.org/wiki/UTF-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question