Skip to content

Instantly share code, notes, and snippets.

@zealfire
Created May 12, 2018 23:05
Show Gist options
  • Save zealfire/dd1208d1674898a2509c1ae87a1a2219 to your computer and use it in GitHub Desktop.
Save zealfire/dd1208d1674898a2509c1ae87a1a2219 to your computer and use it in GitHub Desktop.

CR and LF are control characters, respectively coded 0x0D (13 decimal) and 0x0A (10 decimal).

They are used to mark a line break in a text file. As you indicated, Windows uses two characters the CR LF sequence; Unix only uses LF and the old MacOS ( pre-OSX MacIntosh) used CR.

An apocryphal historical perspective:

As indicated by Peter, CR = Carriage Return and LF = Line Feed, two expressions have their roots in the old typewriters / TTY. LF moved the paper up (but kept the horizontal position identical) and CR brought back the "carriage" so that the next character typed would be at the leftmost position on the paper (but on the same line). CR+LF was doing both, i.e. preparing to type a new line. As time went by the physical semantics of the codes were not applicable, and as memory and floppy disk space were at a premium, some OS designers decided to only use one of the characters, they just didn't communicate very well with one another ;-)

Most modern text editors and text-oriented applications offer options/settings etc. that allow the automatic detection of the file's end-of-line convention and to display it accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment