# Documentation/Calc Functions/HEX2OCT

Jump to navigation Jump to search

HEX2OCT

Add-in

## Summary:

Converts a hexadecimal number (base-16) to its octal (base-8) equivalent. The input hexadecimal number must correspond to a decimal number d in the range -229d < 229.

## Syntax:

HEX2OCT(Number[; Places])

## Returns:

Returns a text string comprising up to 10 octal characters (0…7), which is the octal number in two’s complement form that corresponds to the specified hexadecimal number.

## Arguments:

Number is a string or a number, or a reference to a cell containing one of those types, which gives the hexadecimal number that is to be converted to octal. The hexadecimal number must comprise no more than 10 characters and should correspond to a decimal number in the range -229d < 229. If the hexadecimal number contains any letters (a…f or A…F; the case of these characters is not significant), it must either be in a referenced cell or passed as a string argument in quotation marks.

Places is an integer in the range 1 to 10, or a reference to a cell containing that value, which is the number of octal characters that should be returned for a positive Number. Places is ignored for negative values of Number, when HEX2OCT always returns 10 octal characters. The default for positive values of Number is for the returned string to occupy as many characters as necessary to accommodate the octal representation; however, you can set the value of Places to add leading zeroes where necessary.

• Number should use the standard two's complement representation. In two's complement, positive numbers are hexadecimal 0 to 3777777777 (0 to 229-1 decimal) and negative numbers are hexadecimal FFFFFFFFFF to 4000000000 (-1 to -229 decimal). Negative numbers must be ten digits long with the leftmost digit set to 1; positive numbers can comprise less than 10 digits.
• If Number does not specify a valid hexadecimal number, then HEX2OCT reports an invalid argument error (Err:502). This may arise, for example, if Number contains more than 10 characters or if it contains any character other than 0…9, a…f, or A…F.
• If a hexadecimal value containing one or more letters is passed directly to the function and is not surrounded by quotation marks, HEX2OCT reports a #NAME? error.
• If Number is a string comprising no characters, or a reference to an empty cell, HEX2OCT returns 0 (possibly with leading zeroes, depending on the value of Places).
• Although the content of Number may appear to be decimal if it contains no letters, HEX2OCT will interpret it correctly.
• If Places is non-numeric, then HEX2OCT reports an invalid argument error (Err:502).
• If Places is a non-integer value, then HEX2OCT truncates it to an integer.
• If, after any truncation, Places is less than 1 or greater than 10, HEX2OCT reports an invalid argument error (Err:502).
• If Number is positive and Places is less than the minimum number of characters required to accommodate the octal representation of Number, then HEX2OCT reports an invalid argument error (Err:502).

## Additional details:

The following Wikipedia pages provide useful background information relevant to this function:

## Examples:

Formula Description Returns
=HEX2OCT("1D") Here the function converts the hexadecimal value of 1D (passed as a string) to its octal equivalent of 35. 35
=HEX2OCT(1D) Here the function returns an invalid name error because Calc does not recognize 1D as a number. #NAME?
=HEX2OCT(15) Here the function converts the hexadecimal value of 15 (passed as a number) to its octal equivalent of 25. 25
=HEX2OCT("1d"; 4) Here the function again converts the hexadecimal value of 1d (passed as a string) to its octal equivalent of 35 but also adds two leading zeroes. 0035
=HEX2OCT(D1; D2) where cells D1 and D2 contain 1D (text) and 6 (number) respectively. Here the function again converts the hexadecimal value of 1D (passed via a cell reference on this occasion) to its octal equivalent of 35 but also adds four leading zeroes. 000035
=HEX2OCT("FFE0000000") Here the function converts the minimum allowed hexadecimal value of FFE0000000 (-229 in decimal) to its octal equivalent of 4000000000. 4000000000
=HEX2OCT(-1) Here the function converts the hexadecimal value of FFFFFFFF (-1 in decimal) to its octal equivalent of 7777777777. 7777777777
=HEX2OCT("1FFFFFFF") Here the function converts the maximum allowed hexadecimal value of 1FFFFFFF (229-1 in decimal) to its octal equivalent of 3777777777. 3777777777

HEX2OCT