We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.
Software

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

What is Type Conversion?

By S.A. Keel
Updated: May 16, 2024

Type conversion is a form of type punning, a technique used in computer science and computer software programming in which the data type of a specific entity is changed into a different data type. The concept of type punning came about to work around the specified type system of a programming language so certain effects can be achieved that would otherwise be difficult to do within the confines of the programming language's formal definition. Type conversion, being the most common form of type punning, is possible in virtually all programming languages, though some languages offer additional methods of type punning, such as union or reinterpretation. Some programming style guides suggest against type punning, even though type conversion is frequently used anyway.

Type conversion is also sometimes referred to as typecasting or coercion, depending on the programming language being used. Each programming language has rules on how type conversion can be used successfully. Generally speaking, conversions can take place on either fundamental types or objects.

There are several fundamental data types or classes of data types. One common data type used in mathematical operations is integers, or plain numbers, that can range into the thousands or millions, depending on the number of bits in their width. For example, a 32-bit integer can range from zero through 4,294,967,295, or -2,147,483,648 through 2,147,483,648. Another type is the floating-point number, which is basically any number with a decimal point.

Single characters, such as a letter of the alphabet or a punctuation mark, can also be used as a data type. A string data type is any group or sequence of numbers and/or letters without a break; string lengths are arbitrary, but their size or limit is usually defined in the programming language. The oldest of data types is the Boolean, which is simply either true or false. Other classes of types include algebraic, functions, machine data, and objects. For example, in object-oriented languages, the ancestor of an object can use the type of a parent object so their interactions with each other go more smoothly.

The specifics of type conversion really don't come into play until a particular programming language's rules are taken into consideration. Some language's rules further dictate whether a type conversion is implicit or explicit. An implicit type conversion is most frequently called a coercion and usually takes place at the time a program is compiled from source code into an executable program. This can happen, say, if multiple data types are used in an expression and then a comparison is executed. The type conversion is considered implied, and the compiler handles it automatically; an explicit type conversion is defined in the code of the program. The C programming language makes a distinction between the two, calling an implicit type conversion a coercion, and an explicit type conversion a cast.

A simple example of a common type conversion would be mathematical operations on numbers in a computer program. A computer program receiving a decimal number, a floating-point data type, as input may need to convert the number into an integer data type to perform mathematical operations, or vice versa. This conversion allows the operation to proceed.

EasyTechJunkie is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Discussion Comments
Share
https://www.easytechjunkie.com/what-is-type-conversion.htm
EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.