00- Prepare knowledge

  • A computer can only recognize 0 and 1(because it only recognizes power and power)
  • All data stored on a computer is made up of zeros and ones (the larger the data, the more zeros and ones there are)
  • The unit of measurement in computers is 1 B(Byte) = 8 bits // 00000000 is a Byte // 111111111 is also a Byte // 10101010 is also a Byte // Any combination of eight zeros or ones is a Byte 1 KB = 1024 B 1 MB = 1024KB 1 GB = 1024MB
  • We need to know something about base

Common base

  • binary
  • octal
  • The decimal system
  • hexadecimal

The format and rules of base writing

  • binary
    • Zero, one goes into two
    • Writing format: start with 0B or 0B
    • Such as: 0 b0, 0 b1
  • octal
    • 0,1,2,3,4,5,6,7,8
    • Writing format: starts with 0
    • For example: 00,01,02,03
  • The decimal system
    • 0,1,2,3,4,5,6,7,8,9,10 go one into ten
  • 16 mechanism
    • 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F meet hexadecimal
    • Writing format: start with 0x or 0x
    • Such as: 0 x0, oX0, 0 x1, 0 x2

practice

Use different bases to indicate how many tables there are below

  • binary

  • octal

– a decimal

– Hexadecimal

I’m sorry for the ugly hand drawing

The next step is base conversion

  • Decimal to binary

    • Rule: In addition to two flashbacks take more than
    • Let’s say what our 14 is converted to binary

  • Binary to decimal

  • Decimal to octal

    • It’s like going from decimal to binary
    • Rule: In addition to eight flashback take more than
  • Conversion from decimal to hexadecimal

    • It’s like going from decimal to binary
    • Rule: In addition to sixteen flashbacks take more than
  • Convert octal to decimal

    • It’s like binary to decimal
  • Conversion from hexadecimal to decimal

    • It’s like binary to decimal
  • Binary to octal

  • Binary to hexadecimal

01- What is a Buffer?

Buffer is a class on the Node.js global object that is dedicated to storing bytes of data

Node.js provides an API for manipulating the underlying computer, which only recognizes zeros and ones

So you provide a class dedicated to storing bytes of data

02- How to create a Buffer object

  • Creates a Buffer of the specified size

    • Buffer.alloc(size[, fill[, encoding]])
      Copy the code

  • Creates a Buffer object based on an array/string

    • Buffer.from(string[, encoding])
      Copy the code

03-buffer instance method

1. Convert the data to a string

buf.toString()
Copy the code

2. Write data to Buffer

buf.write(string[, offset[, length]][, encoding])
Copy the code

3. Intercept a new Buffer from the specified position

buf.slice([start[, end]])
Copy the code

04-buffer Static method

1. Check whether an encoding format is supported

Buffer.isEncoding(encoding)
Copy the code

2. Check whether it is a Buffer object

Buffer.isBuffer(obj)
Copy the code

3. Obtain the actual Buffer length

Buffer.byteLength(string[, encoding])
Copy the code

4. Merge the data in Buffer

Buffer.concat(list[, totalLength])
Copy the code