Learn something new every day More Info... by email
Integer conversion is a type of data conversion that is often used in computer programming. Conversion of either constants or variables, sometimes called type conversion, allows these numbers and characters or character strings to be treated in different ways by a program. Integer conversion helps to make a number or character string fit a desired format.
Integers, also called whole numbers, are numbers without any decimal points attached. Programmers might use integer conversion to change a number including a decimal point into an integer. In this kind of integer conversion, the programmer is just “rounding off” a number to come up with a specific result.
Other kinds of integer conversions include converting an integer from a value into a character or part of a character string. These kinds of integer conversions are generally more complex, since it can get confusing to deal with an integer as a number and as a set of characters. Different computer programming languages have their own methods for converting integers from values to character strings.
In integer conversions, and other kinds of type conversion, there are also two different “flavors” for conversion. Programmers refer to these as implicit and explicit conversion. Implicit conversion is when the integers are treated as variables and converted indirectly by a compiler, or function automatically. Explicit conversion is when a specific integer conversion is written concretely into a piece of code using constants. Both of these have their own benefits and disadvantages within a specific programming system.
In explicit conversion, also called casting, there are also different methods of conversion. These are called checked, unchecked, and bit pattern conversion. The difference between checked conversion and unchecked conversion is that in a checked conversion, the program runs a check to see if the variable or constant can be accurately converted, and returns an error message if this is not the case. In an unchecked conversion, an unsuccessful result is simply undefined. In a bit pattern conversion, the raw bit representation is copied.
Integer conversion and other kinds of type conversion are widely used in object-oriented programming. While explicit conversion can be useful, implicit conversions using variables are often part of object oriented programming, where lots of information can be “passed” from one object or class to another. Integer conversion generally helps programmers to enjoy all of the various uses of the common whole number within a computer program.