Numeric Variables Versus Characters
Working with numeric and character types is typical of working with a low-level programming language. High-level programming languages abstract away the detail associated with manipulating the various types of numbers. Being able to manipulate the type of numbers and characters directly is important when programming compact applications that must run quickly.
-
Integers
-
Integers are whole numbers and have no decimal part. When working with integers, unless explicitly told, most programming languages will assume that the end result of an operation is to be an integer and will round unless told otherwise. For example, the expression "4/3" might yield "1" or "2" depending on how the language rounds. Integers are the simplest kinds of numbers most low-level programming languages are capable of representing.
Floating Point
-
Floating point numbers include a decimal point. This type of number is used for performing operations on numbers with a decimal point. Many programming languages will not perform operations on numbers that are of different types or will make assumptions about what the programmer was asking for. This is important to remember when working with floating point numbers. In one programming language, "2.5 + 4" might equal "6.5" and in another might equal "7." Another language might give an error. This depends on how the language chooses to treat numbers of different types.
-
Long
-
Due to storage constraints, the integer type limits how long the number can be before it overflows, taking up extra space in memory. The Long type exists to remedy this problem. Long numbers are numbers that are over a certain length. This length varies depending on the machine on which the language is being run. Long integers need to be typed this way, otherwise the number will overflow and cause errors.
Characters
-
Characters are usually represented one of two ways, in ASCII or in Unicode. These are two different character encodings. Unicode is designed for international use and provides character encodings for most of the languages around the world. ASCII predates Unicode and only supports American English.
-