Documentation/Calc Functions/OCT2HEX

    From The Document Foundation Wiki
    Other languages:


    Function name:

    OCT2HEX

    Category:

    Add-in

    Summary:

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

    Syntax:

    OCT2HEX(Number[; Places])

    Returns:

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

    Arguments:

    Number is a string or a number, or a reference to a cell containing one of those types, which gives the octal number that is to be converted to hexadecimal. The octal number must comprise only the digits 0...7, and must be no more than 10 digits long.

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

    • Number should use the standard two's complement representation, so that positive numbers are octal 0 to 3777777777 (0 to 229-1 decimal) and negative numbers are octal 7777777777 to 4000000000 (-1 to -229 decimal). Negative numbers must be 10 digits long with the leftmost bit set to 1; positive numbers can comprise less than 10 digits.
    • If Number does not specify a valid octal number, then OCT2HEX 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 the digits 0...7.
    • If Number is a string comprising no characters, or a reference to an empty cell, OCT2HEX returns 0 (possibly with leading zeroes, depending on the value of Places).
    • Although the content of Number appears to be decimal, OCT2HEX will interpret it correctly.
    • If Places is non-numeric, then OCT2HEX reports an invalid argument error (Err:502).
    • If Places is a non-integer value, then OCT2HEX truncates it to an integer.
    • If, after any truncation, Places is less than 1 or greater than 10, OCT2HEX 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 hexadecimal representation of Number, then OCT2HEX reports an invalid argument error (Err:502).

    Additional details:

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

    Examples:

    Formula Description Returns
    =OCT2HEX(77) Here the function converts the octal value of 77 (passed as a number) to its hexadecimal equivalent of 3F. 3F
    =OCT2HEX("77"; 4) Here the function again converts the octal value of 77 (passed as a string) to its hexadecimal equivalent of 3F but also adds two leading zeroes. 003F
    =OCT2HEX(D1; D2) where cells D1 and D2 contain the numbers 77 and 6 respectively. Here the function again converts the octal value of 77 (passed via a cell reference) to its hexadecimal equivalent of 3F but also adds four leading zeroes. 00003F
    =OCT2HEX(4,000,000,000) Here the function converts the minimum allowed 10-character octal value of 4000000000 (-229 in decimal) to its hexadecimal equivalent of FFE0000000. FFE0000000
    =OCT2HEX(7,777,777,777) Here the function converts the 10-character octal value of 7777777777 (-1 decimal) to its hexadecimal equivalent of FFFFFFFFFF. FFFFFFFFFF
    =OCT2HEX(3,777,777,777) Here the function converts the maximum allowed 10-character octal value of 3777777777 (229-1 in decimal) to its hexadecimal equivalent of 1FFFFFFF. 1FFFFFFF

    Related LibreOffice functions:

    OCT2BIN

    OCT2DEC

    ODF standard:

    Section 6.19.16, part 2

    Related (or similar) Excel functions:

    OCT2HEX