DEC2HEX Function (LibreOffice Calc)

Engineering Beginner LibreOffice Calc Introduced in LibreOffice 3.0
number-systems hexadecimal engineering encoding bitwise

The DEC2HEX function converts a decimal (base‑10) integer into a hexadecimal (base‑16) string. It supports optional padding and handles negative values using two’s complement representation.

Compatibility

What the DEC2HEX Function Does

  • Converts decimal → hexadecimal
  • Returns a text string
  • Supports optional minimum-length padding
  • Handles negative numbers using two’s complement
  • Useful in engineering, encoding, and bitwise workflows

Syntax

DEC2HEX(number; [places])

Arguments

  • number:
    Decimal integer between –549,755,813,888 and 549,755,813,887.

  • places (optional):
    Minimum length of the returned hex string.
    Pads with leading zeros if necessary.

Basic Examples

Convert decimal to hex

=DEC2HEX(255)
→ "FF"

Convert with padding

=DEC2HEX(255; 6)
→ "0000FF"

Convert a negative number

=DEC2HEX(-10)
→ "FFFFFFFFF6"   (two’s complement)

Advanced Examples

Force 8‑character hex output

=REPT("0"; 8-LEN(DEC2HEX(A1))) & DEC2HEX(A1)

Round‑trip validation

=HEX2DEC(DEC2HEX(A1))

Convert decimal → hex → binary

=DEC2BIN(HEX2DEC(DEC2HEX(A1)))

Extract the low byte

=RIGHT(DEC2HEX(A1; 2); 2)

Use in bitwise logic

=DEC2HEX(BITAND(A1; 255))

Convert a range of values

=ARRAYFORMULA(DEC2HEX(A1:A10))

Edge Cases and Behavior Details

DEC2HEX returns text, not a number

Valid input range

  • Minimum: –549,755,813,888
  • Maximum: 549,755,813,887

Negative numbers use two’s complement

Hex output is always unsigned.

Examples:

  • –1 → "FFFFFFFFFF"
  • –10 → "FFFFFFFFF6"

Behavior details

  • If places is too small → Err:502
  • If places is omitted → no padding
  • If number is out of range → Err:502
  • Hex letters are uppercase (A–F)

Common Errors and Fixes

Err:502 — Invalid argument

Cause:

  • Number outside valid range
  • places < length of hex result
  • Non‑integer input

Fix:

  • Clamp input
  • Increase places
  • Wrap with INT()

Unexpected long hex strings

Cause:

  • Two’s complement for negative numbers

Fix:

  • Use HEX2DEC to interpret
  • Document bit width assumptions

Best Practices

  • Always specify places when consistent width is required
  • Use DEC2HEX for encoding, engineering, and bitwise workflows
  • Use BASE() for arbitrary‑base conversions
  • Normalize hex strings before comparison
  • Document two’s complement behavior for negative values
DEC2HEX is ideal for low‑level engineering, encoding, and bitwise modeling — especially when paired with HEX2DEC, DEC2BIN, and BASE().

Related Patterns and Alternatives

  • HEX2DEC — hex → decimal
  • DEC2BIN / DEC2OCT — other base conversions
  • BASE — general base conversion
  • BITAND / BITOR / BITXOR — bitwise logic
  • TEXT functions — padding and formatting

By mastering DEC2HEX, you can build precise, encoding‑ready engineering models in LibreOffice Calc.

Copyright 2026. All rights reserved.