Pure Programmer
Blue Matrix

Cluster Map

Basic Data Types


Computers can only perform operations on numbers. Modern CPUs can perform operations on integer and floating point numbers. The most basic and most commonly used are the integers. Integers are even used to represent characters based on the character set mappings such as ASCII or Unicode.

To understand the capabilities of the integers supported by the computer, it is important to note that computers do not store integers (or floating point) using the decimal (base 10) digits that we are accustomed to using. Instead computers store numbers using [[binary]] (base 2). In binary there are only two digits: 0 and 1. Therefore a single binary digit or bit, can hold one of the two possible binary values. If we combine two bits, we can represent four different values. With three bits we can represent eight different values and four bits gives us 16 values. This doubling of the number of values represented with each bit added gives us the following formula for the number of values that can be stored with a given number of bits.

values = 2n where n represents the number of bits.

The smallest group of bits that computers work with is a group of eight bits called a byte. A byte allows us to represent 256 different values. Groups of bytes combine to give us larger and larger ranges of value. Because we want to represent negative as well as positive numbers, we use half the range of values to represent negative values. Integers that can store positive or negative numbers are called signed integers.

Integer Specs
# bits# bytes# valuesSigned Range
81256-128 to 127
16265,536-32,768 to 32,767
3244,294,967,296-2,147,483,648 to 2,147,483,647
64818,446,744,073,709,551,616-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

For many years computers that operate primarily on 32-bit integers were common. Modern desktop computers typically operate primarily on 64-bit integers but 32-bit CPUs are still commonly embedded in devices other than desktop computers such as tablets, cell phones, routers, etc.

Integer [[literals]] are represented in our programs much as you would expect using decimal (base 10) notation using the digits 0-9. They can also be written in [[hexadecimal]] notation (base 16) which is handy in some situations. Hexadecimal values are written using the 16 digits 0-9 and A-F. They must be prefaced by the symbol 0x. Hexadecimal notation is a handy way to represent values that easily map to their binary representation as each hexadecimal digit represents exactly four binary digits. The following are examples of valid integer literals in both decimal and hexadecimal notation.

Example Integer Literals


  1. In the table of integer specs above, the number of values is always a number that ends in the digit 6. Why is this?
  2. Integers with 128 bits would give us 2128 ≅ 3.4 x 1038 different values. Is this a useful data type or too excessive?


More ★'s indicate higher difficulty level.

Floating Point

To represent fractional values we need another data type in addition to integers. This is where floating point data types come in. Floating point data types can represent a whole number and a fractional part. There are two commonly used floating point representations: 32-bit singles and 64-bit doubles. The bit patterns of these floating point representations are defined in a specification called [[IEEE 754]] defined in 1984.

Floating Point Specs
(Decimal Digits)
Exponent MinExponent Max

It would seem that [[IEEE singles]] would result in faster computations because they are smaller data types (4 bytes) vs [[IEEE doubles]] (8 bytes). It turns out that computations with [[IEEE doubles]] are faster because this is the native data type used by modern processors. Floating point [[literals]] always represented, therefore, as doubles.

Floating point [[literals]] are written using standard base 10 decimal notation. They can also be written in a form of [[scientific notation]] that uses the letter 'e' to indicate a power of ten multiplier such that a number like 1.23 × 104 is written as 1.23e4. When written in scientific notation we see how the Floating Point Specs listed above apply. The Precision in Decimal Digits refers to the maximum number of digits we can represent in the mantissa (number before the 'e'). The Exponent Min and Max refer to the smallest and largest value of the power of ten (number after the 'e').

Example Floating Point Literals
Fixed PointScientific Notation



More ★'s indicate higher difficulty level.


The simplest of all basic data types is the [[Boolean]], named after [[George Boole]]. [[Booleans]] can only be one of two possible values: true or false. Unfortunately Perl doesn't have a [[Boolean]] data type. Instead it treats 0, '' or undef as false and anything that isn't false as true. This can lead to errors so you must be very careful when dealing with [[Boolean]] expressions in Perl. If you need a [[literal]] value to represent true or false, it is best to stick with 1 and 0, respectively.


  1. Why are Boolean values named after George Boole?


More ★'s indicate higher difficulty level.

Characters and Strings

Computers store characters as integer codes based on a particular coding scheme such as [[ASCII]], [[ISO Latin-1]] or [[Unicode]]. Even so, we treat characters as a distinct type separate from integers. This is because integers support arithmetic operations whereas characters do not. Perl characters can be encoded using multiple bytes so they can represent [[ASCII]]/[[ISO Latin-1]] characters. The use utf8; declaration must appear at the beginning of your Perl program for [[Unicode]] support to be turned on. Character constants are represented only within strings either enclosed in single or double quotes. Alternately the hexadecimal code for a character can be used by prefacing the code by \x or wrapping with \x{} (depending on whether 2 or 4 hexadecimal digits are need to represent the character) and enclosing within a string.

Thus strings are merely a sequence of zero of more characters enclosed in quotes. An empty string (or null string) has no characters. Perl string [[literals]] are enclosed in single or double quotes. Single-quoted strings don't allow variable interpolation whereas double-quoted strings allow [[variable interpolation]].

Example Character & String Literals


  1. Why is ASCII support still important?
  2. Why is UTF-8 encoded Unicode backward compatible with ASCII?
  3. Why is Unicode support so important?
  4. Why is Unicode probably the last character coding scheme that will ever be developed?


More ★'s indicate higher difficulty level.