Data Type

From Conservapedia

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[edit]

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[edit]

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.

Binary-Coded Decimal (BCD) is also used to represent numbers, for instance in COBOL. BCD encodes a digit using 4 bits, thus allowing 2 digits per byte. Plus and minus signs, and decimal points are also represented by one of the 16 possible 4-bit values. Certain bit combinations are invalid as BCD. Because of the encoding method, BCD is less space-efficient than typical integer or floating point values. For instance, a 32-bit integer can represent a value from negative 2 billion to positive 2 billion, whereas a 32-bit BCD has a maximum value of 99,999,999 or -9,999,999. Arithmetic operations with it are also slower than other encodings. However, it can more accurately represent fractional values, and conversion to human-readable numbers is less CPU-intensive.

Strings[edit]

Sometimes called "character strings", strings represent textual data.[1] Computer hardware is typically not optimized for the types of operations that programmers like to do, such as concatenating or inserting, because these operations can make strings change size, requiring moving large blocks of memory around. Many ways of dealing with this problem have been devised over the last 60 years, involving efficiency vs. naturalness trade-offs. Some languages, like C and C++, permit efficient string manipulation, at a cost of programmer naturalness and understandability. Others, like Lisp and Perl, permit natural use of strings at a cost of efficiency. SQL is sort of between the two.

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[edit]

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.

Class types[edit]

Class types define objects. Variables of this type contain instances of the specific class, or a descendant thereof. Used in Object Oriented programming.

Structures[edit]

Structures, or records, are collections of multiple named data types. Some modern languages do not support structures, per se. Instead they use objects, which can be considered a superset of the structure concept. The following is an example of a structure implemented in Pascal.

type tColor = record
                  Red : byte ;
                  Green : byte ;
                  Blue : byte ;
                  Alpha : byte
              end ;

Collections[edit]

Collections represent a group of variables of the same data type. The organization of the collection depends upon the type of collection. Typical collections natively supported by programming languages include arrays, but also can include trees, lists, queues, stacks, etc. Some languages provide iterators which provide a means of processing through each item in the collection.

Enumerations[edit]

Enumerations are user-defined identifiers that are used in place of numeric or string constants.

References[edit]


Categories: [Computer Science] [Data Structures]


Download as ZWI file | Last modified: 03/03/2023 22:08:07 | 12 views
☰ Source: https://www.conservapedia.com/Data_type | License: CC BY-SA 3.0

ZWI signed:
  Encycloreader by the Knowledge Standards Foundation (KSF) ✓[what is this?]