How to Use the BASE and DECIMAL Functions in Google Sheets to Convert Numbers Across Number Systems

Working with technical datasets, embedded hardware identifiers, colour codes, or computer science problems frequently requires translating numbers across various radices. While spreadsheets are predominantly configured for base-10 decimal calculations, Google Sheets provides two specialized engineering functions—BASE and DECIMAL—to seamlessly convert numbers between arbitrary positional number systems ranging from base 2 up to base 36.

Understanding the Syntax of BASE and DECIMAL

Unlike basic formatting adjustments that only modify visual presentation, these functions perform algorithmic mathematical conversions directly inside the formula engine.

The BASE Function Syntax

The BASE function converts a decimal integer into a text representation in another number base:

=BASE(value, radix, [min_length])
  • value: The positive base-10 integer to convert. It must be an integer between 0 and 2^53 – 1.
  • radix: The target number base (between 2 and 36 inclusive). For example, 2 for binary, 8 for octal, 16 for hexadecimal.
  • min_length (Optional): The minimum number of digits in the output string. If the converted number contains fewer digits, Google Sheets automatically pads the result with leading zeros.

The DECIMAL Function Syntax

The DECIMAL function performs the reverse conversion, taking a text string in a specific number base and returning its standard base-10 integer equivalent:

=DECIMAL(value, radix)
  • value: The text string representing the number to be converted. Characters can include digits (0–9) and case-insensitive letters (A–Z) appropriate for the chosen base.
  • radix: The base of the input string (between 2 and 36).

Common Radix Conversion Examples in Google Sheets

The table below illustrates practical conversions using standard computational bases:

Conversion Type Input Value Formula Result Explanation
Decimal to Binary 42 =BASE(42, 2, 8) 00101010 Converts to base-2, padded to 8 bits with leading zeros.
Decimal to Hexadecimal 255 =BASE(255, 16, 2) FF Converts 255 to two-digit uppercase hexadecimal.
Binary to Decimal “10110” =DECIMAL("10110", 2) 22 Calculates 16 + 4 + 2 = 22.
Hexadecimal to Decimal “3E8” =DECIMAL("3E8", 16) 1000 Converts hex “3E8” into base-10 integer 1000.
Base-36 Alphanumeric “SHEETS” =DECIMAL("SHEETS", 36) 1650393088 Decodes base-36 alphanumeric string into raw decimal.

Converting Hex Colour Codes to RGB Components

A classic real-world application of the DECIMAL function involves parsing hex colour codes (such as web colours extracted from design mockups) into red, green, and blue decimal intensities:

  1. Assuming cell A2 contains a six-character hex colour string (e.g., "34A853" without the # symbol):
  2. Extract the red channel intensity (first 2 characters):
    =DECIMAL(MID(A2, 1, 2), 16)
  3. Extract the green channel intensity (middle 2 characters):
    =DECIMAL(MID(A2, 3, 2), 16)
  4. Extract the blue channel intensity (last 2 characters):
    =DECIMAL(MID(A2, 5, 2), 16)

This allows you to compute brightness, contrast ratios, and colour histograms dynamically within your spreadsheet models.

Handling Errors and Input Constraints

When implementing BASE and DECIMAL in dynamic workflows, watch for these common formula exceptions:

  • #NUM! Error in BASE: Occurs when the input number is negative, exceeds the 53-bit integer limit, or when the radix is specified outside the allowed range of 2 to 36.
  • #NUM! Error in DECIMAL: Triggered when a character in the text string does not exist within the specified radix. For example, evaluating =DECIMAL("102", 2) fails because the digit 2 is invalid in binary.
  • #VALUE! Error: Occurs when the radix argument cannot be parsed as a valid numeric integer.
  • Leading Zero Truncation: Because BASE outputs a text string, leading zeros specified by min_length are preserved. However, if you feed the output of BASE into arithmetic formulas without quotes, Google Sheets may interpret numeric outputs as standard base-10 numbers.

Batch Converting Columns with Array Formulas

To convert an entire column of decimal values to zero-padded binary numbers without dragging formulas manually, combine BASE with MAP and LAMBDA:

=MAP(A2:A100, LAMBDA(val, IF(ISBLANK(val), "", BASE(val, 2, 8))))

This dynamic array formula expands down the worksheet, automatically generating clean 8-bit binary strings for every non-empty row.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.