Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

byte-sized bit pattern in C and its relevance?

Tags:

c

I a reading Kerninghan and Ritchie's C programming language book and on page 37 it mentions byte sized bit patterns like :

'\013' for vertical tab .

'\007' for bell character .

My doubts :

  1. What is byte sized in it and and what's a bit pattern ?
  2. What relevance does this hold and where can I apply it ?
  3. Is it in any sense related to escape sequences ?

I can't seem to find any information what so ever about these byte sized bit patterns on the web . please help . thanks .

like image 280
Nikunj Banka Avatar asked Dec 02 '12 03:12

Nikunj Banka


People also ask

What is meant by bit pattern?

A specific layout of binary digits.

How many bytes is a character?

Eight bits are called a byte. One byte character sets can contain 256 characters. The current standard, though, is Unicode which uses two bytes to represent all characters in all writing systems in the world in a single set.


2 Answers

  1. A byte is 8 bits. See here
  2. A bit pattern is the bits that make up the data. E.g. The octal value (i.e. '\007) is converted to the bit pattern (most significant bit first) would be 0000 0111. '\013' would be the bit pattern 0000 1011
  3. You typically use these escape sequences for non-printable characters.
  4. '\007' is an escape sequence. So is '\\'.
like image 92
Ed Heal Avatar answered Sep 18 '22 08:09

Ed Heal


When C was first developed and used the original target was the PDP-11 minicomputer. The PDP-11 had a 16 bit processor. At the time most input was done with some version of a teletype terminal or teleprinter terminal (a keyboard with printed paper rather than a Cathode Ray Tube). Later Cathode Ray Tube types of terminals were put into place such as the DEC-VT100 terminal replacing the paper types of terminals.

These terminals were connected to the host computer using cables to communicate between terminal and host computer. For short cable runs the RS-232 standard was used, often using only three of the 25 pins (transmit, receive, and ground) with software handshake between terminal and host computer. The RS-422 standard was used for longer cable runs. Data transmission rates for direct connections were typically 9600 baud or 14,400 baud.

In the case of remote terminals using the Public Switched Telephone Network to reach the host computer, a modem was used at each end of the connection to convert and unconvert digital signals into acoustic signals for transmission over the telephone line. Characters typed on the terminal key board were transmitted to the host computer over the cable. Most modems used some variation of the defacto Hayes command set standard.

The PDP-11 used the ASCII character set which used a seven bit code to represent each character with the eighth bit being used to implement a simple parity error checking protocol. Later the ASCII character set was extended by using the parity bit as part of the character in order to add characters from European languages to develop the Extended ASCII and the ANSI character sets as well as the ANSI escape code sequences for setting text colors on CRT type displays.

The original ASCII code had a section of codes that were used for terminal control such as to ring the bell, vertical and horizontal tabs, new lines or end of line, etc. There were also codes that were used to create simple protocols such as Start and Stop codes. One such default standard to use the Escape character to indicate the beginning of a control sequence such as the beginning of a text color or to move the cursor to a particular row and column on the display.

With modern Graphical User Interfaces, most of this is fairly old and unused though there are still terminal emulators that which will translate the ANSI escape codes into various display behaviors within a graphical window.

So when Kerninghan and Ritchie were developing C and the Unix operating system on a PDP-11 they were working within an environment of the DEC PDP-11 instruction set, the ASCII character set, and the PDP-11 peripherals such as teleprinters.

So they naturally settled on text strings being composed of 8 bit characters with ways to embed special control characters into the strings in order to ring the bell of the teleprinter and to control the typing head as lines of text are printed.

like image 41
Richard Chambers Avatar answered Sep 21 '22 08:09

Richard Chambers