Type Conversion

In computer science, type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies or type representations. One example would be small integers, which can be stored in a compact format and converted to a larger representation when used in arithmetic computations. In object-oriented programming, type conversion allows programs to treat objects of one type as one of their ancestor types to simplify interacting with them.

Each programming language has its own rules on how types can be converted. In general, both objects and fundamental data types can be converted. In most languages, the word coercion is used to denote an implicit conversion, either during compilation or during run time. A typical example would be an expression mixing integer and floating point numbers (like 5 + 0.1), where the integers are normally converted into the latter. Explicit type conversions can either be performed via built-in routines (or a special syntax) or via separately defined conversion routines such as an overloaded object constructor.

In most Algol-based languages with nested function definitions, such as Ada, Delphi, Modula 2 and Pascal, conversion and casting are distinctly different concepts. In these languages, conversion refers to either implicitly or explicitly changing a value from one data type to another, e.g. a 16-bit integer to a 32-bit integer. The storage requirements may change as a result of the conversion. A loss of precision or truncation may also occur. The word cast, on the other hand, refers to explicitly changing the interpretation of the bit pattern representing a value from one type to another. For example 32 contiguous bits may be treated as an array of 32 booleans, a two character Unicode string, an unsigned 32-bit integer or an IEEE single precision floating point value. While the storage requirements are never changed, it still requires knowledge of low level details such as representation format, byte order, and alignment requirements in order to be meaningful.

In the C family of languages and Algol 68, the word cast typically refers to an explicit type conversion (as opposed to an implicit conversion), regardless of whether this is a re-interpretation of a bit-pattern or a real conversion.

Read more about Type Conversion:  C#, Eiffel

Other articles related to "type conversion, types, conversions, conversion, type":

Quartz Composer - Native Datatypes - Type Conversion
... Data can usually be converted to other types transparently. 3.0, the connections between patches change color to indicate conversions that are taking place ... Yellow connections mean no conversion is taking place, Orange indicates a possible loss of data from conversion (Number to Index), and Red indicates a ...
Type Inference - Nontechnical Explanation
... In most programming languages, all values have a type explicitly declared at compile time, limiting the values a particular expression can take on at run-time ... However, historically, if the type of a value is known only at run-time these languages are dynamically typed ... In other languages, the type of an expression is known only at compile time these languages are statically typed ...
Type Conversion - Eiffel - Example
... Using the.Net type libraries, particularly with commonly used types such as strings, poses a conversion problem ... in many cases, for example when calling.Net methods which expect items of the.Net type to be passed as arguments ... So, the conversion of these types back and forth needs to be as seamless as possible ...
Flight Training - Type Conversion
... A type conversion commonly known throughout Australia and Europe as an endorsement, or in the United States as a "type rating", is the process undertaken by a pilot to update their ...

Famous quotes containing the words conversion and/or type:

    The conversion of a savage to Christianity is the conversion of Christianity to savagery.
    George Bernard Shaw (1856–1950)

    It took six weeks of debate in the Senate to get the Arms Embargo Law repealed—and we face other delays during the present session because most of the Members of the Congress are thinking in terms of next Autumn’s election. However, that is one of the prices that we who live in democracies have to pay. It is, however, worth paying, if all of us can avoid the type of government under which the unfortunate population of Germany and Russia must exist.
    Franklin D. Roosevelt (1882–1945)