DEC2OCT Function (LibreOffice Calc)
The DEC2OCT function converts a decimal (base‑10) integer into an octal (base‑8) string. It supports optional padding and handles negative values using two’s complement representation.
Compatibility
▾| Excel | ✔ |
| Gnumeric | ✔ |
| Google_sheets | ✔ |
| Libreoffice | ✔ |
| Numbers | ✔ |
| Onlyoffice | ✔ |
| Openoffice | ✔ |
| Wps | ✔ |
| Zoho | ✔ |
What the DEC2OCT Function Does ▾
- Converts decimal → octal
- Returns a text string
- Supports optional minimum-length padding
- Handles negative numbers using two’s complement
- Useful in engineering, encoding, and legacy systems modeling
Syntax ▾
DEC2OCT(number; [places])
Arguments
-
number:
Decimal integer between –536,870,912 and 536,870,911. -
places (optional):
Minimum length of the returned octal string.
Pads with leading zeros if necessary.
Basic Examples ▾
Convert decimal to octal
=DEC2OCT(64)
→ "100"
Convert with padding
=DEC2OCT(64; 6)
→ "000100"
Convert a negative number
=DEC2OCT(-10)
→ "7777777766" (two’s complement)
Advanced Examples ▾
Force 8‑character octal output
=REPT("0"; 8-LEN(DEC2OCT(A1))) & DEC2OCT(A1)
Round‑trip validation
=OCT2DEC(DEC2OCT(A1))
Convert decimal → octal → binary
=DEC2BIN(OCT2DEC(DEC2OCT(A1)))
Extract the low octal digit
=RIGHT(DEC2OCT(A1; 3); 1)
Use in bitwise logic (via decimal conversion)
=DEC2OCT(BITAND(A1; 7))
Convert a range of values
=ARRAYFORMULA(DEC2OCT(A1:A10))
Edge Cases and Behavior Details ▾
DEC2OCT returns text, not a number
Valid input range
- Minimum: –536,870,912
- Maximum: 536,870,911
Negative numbers use two’s complement
Octal output is always unsigned.
Examples:
- –1 →
"7777777777" - –10 →
"7777777766"
Behavior details
- If places is too small → Err:502
- If places is omitted → no padding
- If number is out of range → Err:502
- Octal digits range from 0–7 only
Common Errors and Fixes ▾
Err:502 — Invalid argument
Cause:
- Number outside valid range
- places < length of octal result
- Non‑integer input
Fix:
- Clamp input
- Increase places
- Wrap with INT()
Unexpected long octal strings
Cause:
- Two’s complement for negative numbers
Fix:
- Use OCT2DEC to interpret
- Document bit width assumptions
Best Practices ▾
- Always specify places when consistent width is required
- Use DEC2OCT for legacy systems, engineering, and encoding workflows
- Use BASE() for arbitrary‑base conversions
- Normalize octal strings before comparison
- Document two’s complement behavior for negative values
DEC2OCT is ideal for legacy engineering systems, embedded workflows, and encoding tasks — especially when paired with OCT2DEC, DEC2BIN, and BASE().
Related Patterns and Alternatives ▾
- OCT2DEC — octal → decimal
- DEC2BIN / DEC2HEX — other base conversions
- BASE — general base conversion
- BITAND / BITOR / BITXOR — bitwise logic
- TEXT functions — padding and formatting
By mastering DEC2OCT, you can build precise, encoding‑ready engineering models in LibreOffice Calc.