What do the first 32 characters of the ascii table do

asciicontrol-characters

The first 32 characters of the ASCII table (0x00 – 0x1F) are all of the non-printable characters (with the exception of 'DEL' which comes at the end of the table).

What are these used for, other than borking your terminal when you cat a binary file?

A few of them are obvious:

   Oct   Dec   Hex   Char
   ----------------------------------------------
   000   0     00    NUL '\0'                    

   007   7     07    BEL '\a' (bell)             
   010   8     08    BS  '\b' (backspace)        
   011   9     09    HT  '\t' (horizontal tab)   
   012   10    0A    LF  '\n' (new line)         
   013   11    0B    VT  '\v' (vertical tab)     
   014   12    0C    FF  '\f' (form feed)        
   015   13    0D    CR  '\r' (carriage ret)     

   033   27    1B    ESC (escape)                

others, such as

   020   16    10    DLE (data link escape)
   021   17    11    DC1 (device control 1)
   022   18    12    DC2 (device control 2)
   023   19    13    DC3 (device control 3)
   024   20    14    DC4 (device control 4)

I've never seen used.

Are ACK, NAK and SYN the same bytes used for the three way handshake in TCP, or are they simply analogous?

Edit: see Eric Raymond's Things Every Hacker Once Knew

If you learned your chops after 1990 or so, the mysterious part of
this is likely the control characters, code points 0-31. You probably
know that C uses NUL as a string terminator. Others, notably LF = Line
Feed and HT = Horizontal Tab, show up in plain text. But what about
the rest?

Many of these are remnants from teletype protocols that have either
been dead for a very long time or, if still live, are completely
unknown in computing circles. A few had conventional meanings that
were half-forgotten even before Internet times. A very few are still
used in binary data protocols today.

Best Answer

These are called control codes and were meant to tell the actual terminal you were on to do something, rather than pass through to display something. Some of them, such as BEL (0x07), go so far back as to when terminals were actual teletypewriters (in this, 0x07 would ring the physical bell in the teletype).

DLE is meant to work like ESC - once the terminal receives it, further incoming characters are meant to be a command or other communication to the terminal, and not to be output to the actual device itself. Though I've never witnessed an actual use of it.

ACK, NAK, and SYN (and many others like SOH start of header, STX start of text, ETX end of text) could be used to implement a protocol, but weren't designed with TCP/IP in mind. TCP/IP indicates that by setting bits in a header, not by transmitting an entire ASCII code. These may be useful if doing something like transmitting files over a 56k modem. I know serial/modem protocols like ZModem use a couple of these, and I'm sure there's other serial/56k-modem based stuff that does.

This chart knows more than I do about them, including the what the DC1, DC2, DC3, and DC4 codes were meant for.

Related Question