Carriage return different lines and escape characters and ASCII values-(with ASCII code table)

Source: Internet
Author: User
Tags ftp ftp client

The difference between Linux and Windows return line break

source of the problem: "Carriage return" (carriage return) VS "line feed"
Before the computer appeared, there was a gadget called a telex typewriter (teletype Model 33) that could play 10 characters per second. But it has a problem, that is, when the line is finished, it will take 0.2 seconds to hit two characters. If there are new characters coming in this 0.2 seconds, then this character will be lost.
So, the developers think of a way to solve this problem, is to add two after each line to end the character. One is called "carriage return", which tells the typewriter to position the printhead at the left border, and the other is called "line break", telling the typewriter to move the paper down one line.
This is the origin of "line break" and "carriage return", from their English name can also be seen in one or two.
Later, the computer invented, these two concepts are also like to the computer. At that time, memory was expensive, and some scientists thought it would be too wasteful to add two characters at the end of each line. So, there was a disagreement.
Unix system, the end of each line only "< line >", that is "\ n", the Windows system, each line at the end of the "< newline >< Enter >", that is "\n\r", Mac system, the end of each line is "< Enter >". A direct consequence of this is that if the file under the Unix/mac system is opened in Windows, all the text will be turned into one line, and if the files in Windows are opened under Unix/mac, a ^m symbol may appear at the end of each line.

dos and Windows use carriage return + newline cr/lf to represent the next line,

Unix/linux uses the newline character LF to indicate the next line,

the Mac OS system uses a carriage return CR to represent the next line.

The CR symbol ' \ r ' indicates that the decimal ASCII code is 13 and the hexadecimal code is 0x0d;

lf using the ' \ n ' notation, the ASCII code is 10 and 16 is 0x0a. So line breaks in the Windows platform are represented in a text file using 0d 0a two bytes, while the line breaks on UNIX and Apple platforms are expressed in 0a or 0d of bytes.

The runtime on the general operating system automatically determines the text file's wrapping format. If a program runs on Windows, it generates a text file in CR/LF format, while running on Linux generates a text file that is wrapped in the LF format. A file file that uses another line break on one platform can cause unexpected problems, especially when editing program code. Sometimes the code appears normal in the editor, but when you edit it, the error occurs because of a line break. Many text/code editors have a newline character conversion feature that allows you to swap line breaks in text files in different formats.

when using FTP software to transfer files between different platforms, in ASCII text mode transfer mode, some FTP client programs automatically convert to the line format. The number of bytes of files passed through this transfer may vary. If you do not want FTP to modify the original file, you can use Bin mode ( Binary mode) transmits text.

When you convert UNIX to Windows format, you can use Unix2dos or win2unix-r (-R for the opposite direction)

All the escape characters and their corresponding meanings:

Escape character Significance ASCII code value (decimal)
\a Bell (BEL) 007
\b BACKSPACE (BS) to move the current position to the previous column 008
\f Page Break (FF), moving the current position to the beginning of the next page 012
\ n Line Break (LF), move the current position to the beginning of the next line 010
\ r Enter (CR) to move the current position to the beginning of the bank 013
\ t Horizontal tab (HT) (jumps to the next tab position) 009
\v Vertical tabulation (VT) 011
\\ Represents a backslash character ' \ ' 092
\' Represents a single quotation mark (apostrophe) character 039
\" Represents a double-quote character 034
/ Null character (NULL) 000
\ddd Any character represented by a 1 to 3-bit octal number Three-bit octal
\xhh Any character represented by 1 to 2 hexadecimal digits Two-bit hexadecimal
Note: Differentiate, Slash: "/" with backslash: "\", not interchangeable here

Information is represented on a computer by binary notation, which is difficult to understand. Therefore, the computer is equipped with input and output devices, the main purpose of which is to be in a human readable form to display information on these devices for human reading comprehension. In order to ensure the correct information exchange between human and equipment, equipment and computer, people compiled a unified information exchange code, this is the ASCII code table, its full name is "American Information Interchange Standard code".

octal hexadecimal decimal character octal hexadecimal decimal character
00 00 0 Nul 100 40 64 @
01 01 1 Soh 101 41 65 A
02 02 2 Stx 102 42 66 B
03 03 3 Etx 103 43 67 C
04 04 4 EoT 104 44 68 D
05 05 5 Enq 105 45 69 E
06 06 6 Ack 106 46 70 F
07 07 7 Bel 107 47 71 G
10 08 8 Bs 110 48 72 H
11 09 9 Ht 111 49 73 I
12 0a 10 nl 112 4a 74 J
13 0b 11 Vt 113 4b 75 K
14 0c 12 Ff 114 4c 76 L
15 0d 13 Er 115 4d 77 M
16 0e 14 So 116 4e 78 N
17 0f 15 Si 117 4f 79 O
20 10 16 Dle 120 50 80 P
21st 11 17 Dc1 121 51 81 Q
22 12 18 Dc2 122 52 82 R
23 13 19 Dc3 123 53 83 S
24 14 20 Dc4 124 54 84 T
25 15 21st Nak 125 55 85 U
26 16 22 Syn 126 56 86 V
27 17 23 eTB 127 57 87 W
30 18 24 Can 130 58 88 X
31 19 25 Em 131 59 89 Y
32 1a 26 Sub 132 5a 90 Z
33 1b 27 Esc 133 5b 91 [
34 1c 28 Fs 134 5c 92 \
35 1d 29 Gs 135 5d 93 ]
36 1e 30 Re 136 5e 94 ^
37 1f 31 us 137 5f 95 _
40 20 32 Sp 140 60 96 '
41 21st 33 ! 141 61 97 A
42 22 34 " 142 62 98 B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.