Data type

From Conservapedia
This is an old revision of this page, as edited by Eac (Talk | contribs) at 22:24, November 16, 2018. It may differ significantly from current revision.

Jump to: navigation, search

A data type is essentially a rule for how the underlying bits of a value are interpreted. Because of this, the number of data types is practically unlimited. However, there are certain basic data types that are provided by most programming languages. These can be grouped into boolean, numeric, string, and pointer.

Booleans

Boolean values represent one of two values: true and false. As such, they can be represented by a single bit. However, most compilers use the native word size worth of bits to represent a single boolean value. The interpretation of the bits varies somewhat between different languages, but typically if the least significant bit is set to 0, the value is interpreted as false. If the least significant bit is 1, the value is interpreted as true.

Numerics

Numeric values represent numbers. Most programming languages provide both integer and real data types. Further, many languages support several sizes of both types of numbers. The default integer size usually depends upon the underlying hardware. On a 32-bit CPU, the default integer size will also be 32 bits. It is typical that the compiler will support a maximum integer size that is twice the underlying hardware word size (for instance, 64-bit integers on a 32-bit CPU), and a minimum integer size of 1 byte. Integers can be signed, or unsigned. Signed integers use the most significant bit as the sign (set to indicate negative, clear to indicate positive), thus a 16-bit signed integer can represent a number between -32768 and 32767, inclusive. An unsigned 16-bit integer can represent a number between 0 and 65535. Most languages use 2s-complement encoding for interpreting the underlying bits.

In a like manner, floating point values come in various sizes, depending upon the floating-point standard that is used. Typically single precision represents a 32-bit floating-point value, and double precision represents a 64-bit value.

Strings

String values represent textual data. The representation of the text is dependent upon the encoding method. For instance, a Unicode-16 string will use two bytes per character, whereas a string encoded with the Ansi (ASCII) standard represents one character per byte. A UTF-8 encoded string uses a variable number of bytes per character. The encoding indicates how the bits in each character translate to a specific glyph. For instance, the byte value of 65 indicates the uppercase "A" character in the Ansi and UTF-8 encoding. The maximum size of string data is language- and implementation-dependent.

Pointers

A pointer represents an address in memory. This allows indirection. The memory address indicated by the pointer typically contains data of a specific type. For instance, a pointer to an integer.