Documentation/Calc Functions/BIN2OCT

From The Document Foundation Wiki
Jump to navigation Jump to search

Function name:

BIN2OCT

Category:

Add-in

Summary:

Converts a binary number (base-2) to its octal (base-8) equivalent. The input binary number must correspond to a decimal number d in the range -512 ≤ d < 512.

Syntax:

BIN2OCT(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 binary number.

Arguments:

Number is a string or a number, or a reference to a cell containing one of those types, which gives the binary number that is to be converted to octal. The binary number must comprise only the digits 0 and 1, 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 BIN2OCT 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 octal 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 binary 0 to 111111111 (0 to 511 decimal) and negative numbers are binary 1111111111 to 1000000000 (-1 to -512 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 binary number, then BIN2OCT 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 and 1.
  • If Number is a string comprising no characters, or a reference to an empty cell, BIN2OCT returns 0 (possibly with leading zeroes, depending on the value of Places).
  • Although the content of Number appears to be decimal, BIN2OCT will interpret it correctly.
  • If Places is non-numeric, then BIN2OCT reports an invalid argument error (Err:502).
  • If Places is a non-integer value, then BIN2OCT truncates it to an integer.
  • If, after any truncation, Places is less than 1 or greater than 10, BIN2OCT 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 BIN2OCT 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
=BIN2OCT(111111) Here the function converts the binary value of 111111 (passed as a number) to its octal equivalent of 77. 77
=BIN2OCT("111111"; 4) Here the function again converts the binary value of 111111 (passed as a string) to its octal equivalent of 77 but also adds two leading zeroes. 0077
=BIN2OCT(D1; D2) where cells D1 and D2 contain the numbers 111111 and 6 respectively. Here the function again converts the binary value of 111111 (passed via a cell reference) to its octal equivalent of 77 but also adds four leading zeroes. 000077
=BIN2OCT(1000000000) Here the function converts the minimum allowed 10-character binary value of 1000000000 (-512 decimal) to its octal equivalent of 7777777000. 7777777000
=BIN2OCT(1111111111) Here the function converts the 10-character binary value of 1111111111 (-1 decimal) to its octal equivalent of 7777777777. 7777777777
=BIN2OCT(111111111) Here the function converts the maximum allowed 10-character binary value of 111111111 (511 decimal) to its octal equivalent of 777. 777

Related LibreOffice functions:

BIN2DEC

BIN2HEX

ODF standard:

Section 6.19.6, part 2

Equivalent Excel functions:

BIN2OCT