Conversion Functions

Conversion functions fall into the following categories: number systems, the binary system, one’s complement, and two’s complement.

This category contains a series of conversion functions that convert numbers from one number system to another.

The most frequently used and most familiar number system is the decimal system, which works with ten distinct symbols and is derived from our ten fingers. In the English language, this connection can still be found: digit can mean finger as well as number.

With the development of data processing, a need arose for a number system that would accommodate the technical factors of the former calculating machines. The general opinion is that the binary system was introduced because calculating machines were binary calculators, and they were able to work with only two states, on and off. (By the way, in 1943, Konrad Zuse built the first programmable binary calculator, the Z3.)

In addition to the familiar decimal system, there are three other systems that are used in calculation technology. Because Excel can use these four number systems, twelve conversion functions are needed: four number systems can each be converted into the three others.

The number systems are:

The number in parentheses is the base for each number system and thus the number of the digits this number system has. Because the hexadecimal system requires more digits than we have available, the missing digits are represented by the letters A through F. (Not to be confused with the hexagesimal system (actually, the sexagesimal system) with a base of 60, which is used to measure angles, geographic lengths and widths, and time. It is the foundation for old numbering terms such as dozen or great gross as well.) Table 17-5 lists the number systems.

Because the binary system allows only two values per number position, binary numbers can quickly become very long and are difficult to read. Therefore, either of the following can be done:

For example, consider this:

2011 (decimal) = 11111011011 (binary) = 3733 (octal) = 7DB (hexadecimal)

It is obvious that the number system with the largest base (hexadecimal here) is using the fewest digits.

In general, the relationship between the value range M, which can be expressed with a number of a certain length in a base-B number system, and the number of digits n is

M = Bn

For example, eight digits (n = 8) in the binary system (B = 2) can express M = 28 = 256 numbers as its maximum. The value range is 0 through 255. Because only positive numbers can be represented this way, these numbers are called unsigned integers. (This corresponds to the data type Byte in Microsoft Visual Basic for Applications [VBA].)

We are familiar with negative numbers with a minus sign in front of them. For a computer with its binary system (based on the two symbols 0 and 1), there is no space for a third symbol, which is the leading sign. Therefore, the leftmost binary number—the most significant bit (MSB)—is reserved to represent negative numbers. Negative numbers have a 1 in this position, and positive numbers have a 0.

SyntaxBIN2DEC(Number)

Definition. This function converts a binary number into a decimal number.

Argument

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate the BIN2DEC() function.

  • =BIN2DEC(1110) returns 14.

  • =BIN2DEC(111111111) returns 511.

  • =BIN2DEC(1111111111) returns –1.

  • =BIN2DEC(1111111110) returns –2.

The worksheet in Figure 17-1 contains many additional examples, including the conversion into the octal and hexadecimal systems.

Syntax. BIN2HEX(Number,Places)

Definition. This function converts a binary number into a hexadecimal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

ExamplesThe following examples illustrate this function.

You can find additional examples in the »examples for BIN2DEC().

Syntax. BIN2OCT(Number,Places)

Definition. This function converts a binary number into an octal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate this function.

You can find additional examples in the examples for BIN2DEC().

SyntaxDEC2BIN(Number,Places)

Definition. This function converts a decimal number into a binary number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate how to use DEC2BIN().

The worksheet in Figure 17-2 contains many additional examples, including the conversion into the octal and hexadecimal systems.

Syntax. DEC2HEX(Number,Places)

Definition. This function converts a decimal number into a hexadecimal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate the function.

You can find additional examples in the examples for DEC2BIN() in DEC2BIN().

Syntax. DEC2OCT(Number,Places)

Definition. This function converts a decimal number into an octal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

ExamplesThe following examples illustrate this function.

You can find additional examples in the examples for DEC2BIN() in DEC2BIN().

Syntax. HEX2BIN(Number,Places)

Definition. This function converts a hexadecimal number into a binary number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. Here are examples that illustrate this function.

The worksheet in Figure 17-3 contains many additional examples, including the conversion into the decimal and octal systems.

Syntax. HEX2DEC(Number)

Definition. This function converts a hexadecimal number into a decimal number.

Arguments

The (optional) Places argument is not necessary and not available, because the goal to display leading zeros can easily be reached by formatting the cells.

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples show how to use HEX2DEC().

  • =HEX2DEC("E") returns 14.

  • =HEX2DEC("155") returns 341.

  • =HEX2DEC("FFFFFFFFFF") returns –1.

You can find additional examples in the examples for HEX2BIN() in HEX2BIN().

Syntax. HEX2OCT(Number,Places)

Definition. This function converts a hexadecimal number into an octal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

ExamplesThe following examples illustrate this function.

You can find additional examples in the examples for HEX2BIN() in HEX2BIN().

Syntax. OCT2BIN(Number,Places)

Definition. This function converts an octal number into a binary number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate this function.

The worksheet in Figure 17-4 contains many additional examples, including the conversion into the decimal and hexadecimal systems.

Syntax. OCT2DEC(Number)

Definition. This function converts an octal number into a decimal number.

Argument

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

Examples. The following examples illustrate OCT2DEC().

  • =OCT2DEC(16) returns 14.

  • =OCT2DEC(525) returns 341.

  • =OCT2DEC(7777777777) returns FFFFFFFFFF (corresponds to –1decimal).

  • =OCT2DEC(7777777777,4)) also returns FFFFFFFFFF (corresponds to –1decimal).

You can find additional examples in the examples for OCT2BIN() in OCT2BIN().

SyntaxOCT2HEX(Number,Places)

Definition. This function converts an octal number into a hexadecimal number.

Arguments

Background. See the detailed description in the section titled Number Systems in the introduction to these functions (Number Systems).

ExamplesThe following examples illustrate OCT2HEX():

You can find additional examples in the examples for OCT2BIN() in OCT2BIN().

Syntax. CONVERT(Number,From_Measurement_Unit,To_Measurement_Unit)

Definition. This function performs conversions between different measurement systems.

Arguments

CONVERT() accepts for From_Measurement_Unit and To_Measurement_Unit the text values listed in tables in this section as measurement units, which must be put within quotation marks. If these arguments contain cell references, the text in the included cells do not need to be put into quotation marks, because the rules implemented in Excel also mark these text values as text without quotation marks. Pay attention to capitalization! If you don’t, you might get the error message #NV.

Some measurement units can also be written differently. In Table 17-6 through Table 17-15, the various measurement systems are sorted by category.

Table 17-16 lists the increase and decrease factors as well as the unit prefixes. The abbreviated unit prefixes can be used for all metric specifications of From_Measurement_Unit and To_Measurement_Unit.

Background. Traditionally, nonmetric measurements are used in the United States—that is, measurements that are not based on the centimeter-gram-second (CGS) system. In scientific, commercial, and official communication on an international level, only the international units system (SI system) is used, which is becoming more prominent in the United States as well. The conversion between the U.S. and the international units isn’t always easy. The CONVERT() function can save you a lot of work here.

CONVERT() can change a metric length specification into yards (and the other way around). However, the units you want to convert must come from the same category. For example, you obviously cannot convert time specifications into length measurements.

Examples. For each possibility of this function, you can find an example in Figure 17-5.