Node:Machine-level operators, Next:Questions 18, Previous:The comma operator, Up:Advanced operators
Machine-level operators
Bits and Bytes. Flags. Shifting.
Bits (or binary digits), the values 0 and 1, are the lowest-level software objects in a computer; there is nothing more primitive. C gives programmers full access to bits and bit sequences, and even provides high-level operators for manipulating them.
All computer data whatsoever is composed of bit strings. The word "string" is being used here in its more general sense of sequence; do not confuse the usage with "text string". Although all text strings are bit strings, not all bit strings are text strings.
The only difference between a text string and a floating-point value is the way we interpret the pattern of bits in the computer's memory. For the most part, we can simply ignore the low level of the computer in which computer data appears as bit strings. Systems programmers, on the other hand, such as those who wrote GNU/Linux, must frequently manipulate bits directly in order to handle flags.
A flag is a bit in a bit string that can be either set (1)
or cleared (0). We have run across a few flags already, such as
the various flags passed to the GNU C Library functions open
; the
flags O_RDONLY
and O_WRONLY
are actually macros that
specify binary values, which can be manipulated and examined with binary
OR and similar functions. Flags are normally declared as integers in C.
Programmers who perform bit operations on a regular basis often use either octal (base-8) or hexadecimal (base-16) numbers, because every octal digit specifies exactly three bits, and every hexadecimal digit specifies four.