How to use the BASE function
What is the BASE function?
The BASE function converts a decimal number into a text representation with a given radix (base).
Table of Contents
1. Introduction
What is a radix (base)?
The radix or base refers to the number of unique digits in numeral systems that represents the numbers. Common radices are 2 (binary), 8 (octal), 10 (decimal), 16 (hexadecimal).
Changing the radix changes the digit representations but the numeric values are equivalent. The radix determines the inventory of digits used to express values.
What is a text representation?
The BASE function takes numbers as input, however, the output is a text string. This limits Excel's capabilities, for example performing arithmetic calculations to the converted text value are not possible unless you convert the text string back to the decimal system.
What is the decimal numeral system?
The decimal system is the numbers we use every day: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 It is based on the radix (base) of 10, this means there are 10 digits: 0 to 9.
What base conversion functions does Excel have?
These functions convert from the decimal system to the binary, octal and hexadecimal systems.
DEC2BIN | DEC2OCT | DEC2HEX
These functions convert from the binary system to the decimal, octal and hexadecimal systems.
BIN2DEC | BIN2OCT | BIN2HEX
These functions convert from the octal system to the binary, decimal and hexadecimal systems.
OCT2DEC | OCT2BIN | OCT2HEX
These functions convert from the hexadecimal system to the binary, octal and decimal systems.
HEX2BIN | HEX2DEC | HEX2OCT
These functions are located in the "Engineering" category.
Is there a function that converts from any numeral system to the decimal system?
Yes, the DECIMAL function lets you convert numbers to the decimal system.
The DECIMAL function converts a text representation of a number in a given base into a decimal number.
Function syntax: DECIMAL(text, radix)
2. Syntax
BASE(number, radix, [min_length])
number | Required. The number that you want to convert. Must be an integer greater than or equal to 0 (zero) and less than 2^53. |
radix | Required. The base of the number you want it to convert into. 2 <= radix <= 36. |
[min_length] | Optional. The minimum length of the returned string. [min_length] must be an integer greater than or equal to 0 (zero). |
Use the min_length argument to add leading zeros to the resulting value. BASE(16,2) returns 10000, however, BASE(16,2,8) returns 00010000.
The DC2BIN function also allows you to convert numbers into binary values.
Recommended articles
The DEC2BIN function converts a decimal number to a binary number. What is a decimal number? The decimal system is […]
The DECIMAL function converts a text representation of a number in a given base into a decimal number.
Recommended articles
What is the DECIMAL function? The DECIMAL function converts a text representation of a number in a given base into […]
3. Example 1
Convert decimal number 41 to its binary representation?
Here are the arguments:
- number: 41 (This is the number you want to convert from)
- radix: 2 which means binary. (This is the base of the number you convert it to)
Formula in cell C5:
The formula in cell C5 returns the following text string: "101001". It is the binary representation of decimal number 41.
Here is how to calculate the binary representation of decimal number 41:
- Divide 41 by 2. 41/2 = 20 and the reminder is 1.
- Divide 20 by 2. 20/2 = 10 and the reminder is 0 (zero).
- Divide 10 by 2. 10/2 = 5 and the reminder is 0 (zero).
- Divide 5 by 2. 5/2 = 2 and the reminder is 1.
- Divide 2 by 2. 2/2 = 1 and the reminder is 0 (zero).
- Divide 1 by 2. 1/2 = 0 and the reminder is 1.
The result is the reminders from bottom to top: 101001. This binary value matches the result in cell C5.
4. Example 2
Convert decimal number 16777214 to its hexadecimal representation with a minimum length of 6 characters?
Here are the arguments:
- number: 16777214 (This is the number you want to convert from)
- radix: 16 which means hexadecimal. (This is the base of the number you convert it to)
- [min_length]: 6 (The smallest number of characters)
Formula in cell C5:
The formula in cell C5 returns the following text string: "FFFFFE". It is the hexadecimal representation of decimal number 16777214.
Here is how to calculate the hexadecimal representation of decimal number 16777214:
- 16777214/16 = 1048575 and the reminder is 14. E is the hexadecimal representation of decimal number 14.
- 1048575/16 = 65535 and the reminder is 15. F is the hexadecimal representation of decimal number 15.
- 65535 /16 = 4095 and the reminder is 15. F is the hexadecimal representation of decimal number 15.
- 4095/16 = 255 and the reminder is 15. F is the hexadecimal representation of decimal number 15.
- 255/16 = 15 and the reminder is 15. F is the hexadecimal representation of decimal number 15.
- 15/16 = 0 and the reminder is 15. F is the hexadecimal representation of decimal number 15.
The result is the reminders from bottom to top: "FFFFFE". This hexadecimal value matches the result in cell C5.
5. Example 3
Calculate the total of two hexadecimal numbers: FFA and 4EA? Provide the result also in hexadecimal.
The image above shows the hexadecimal values specified in cells C2 and C3, the radix is in cell C4.
The formula in cell C7 adds the hexadecimal values and returns a total or sum.
Formula in cell C7:
Actually, in detail the formula converts the hexadecimal values to decimal values then adds the decimal values to create a total. At last, the formula converts the sum back to a hexadecimal value.
Explaining formula in cell C7
The formula in cell C7 must be entered as an array formula if you use an Excel version earlier than Excel 365. Here is how:
- Type or copy/paste the formula to the formula bar.
- Press and hold both CTRL and SHIFT keys
- Press Enter once.
- Release all keys.
The formula changes to this:
{=BASE(SUM(DECIMAL(C2:C3,C4),C4)}
Don't enter the curly brackets yourself, they appear automatically if you followed the above steps.
Step 1 - Convert hexadecimal values to decimal values
The DECIMAL function converts a text representation of a number in a given base into a decimal number.
Function syntax: DECIMAL(text, radix)
DECIMAL(C2:C3,C4)
becomes
DECIMAL({"FFA";"4EA"},16) and returns {4090;1258}.
Step 2 - Calculate a total based on the decimal numbers
The SUM function allows you to add numerical values, the function returns the sum in the cell it is entered in. The SUM function is cleverly designed to ignore text and boolean values, adding only numbers.
Function syntax: SUM(number1, [number2], ...)
SUM(DECIMAL(C2:C3,C4))
becomes
SUM({4090;1258}) and returns 5348.
Step 3 - Convert decimal back to hexadecimal
BASE(SUM(DECIMAL(C2:C3,C4)),C4)
becomes
BASE(5348) and returns 14E4.
6. Example 4
Calculate the difference between the two hexadecimal numbers: FFA and 4EA? Provide the result also in hexadecimal.
Here are the arguments:
- number1: FFA
- numbers2: 4EA
- radix: 16
Formula in cell C7:
This formula calculates "FFA" minus "4EA" and returns the difference: B10. In greater detail, the formula converts the hexadecimal values to decimal values, then performs subtraction and lastly converts the difference back to hexadecimal.
7. Function not working
The BASE returns
- the #NUM! error value If Number, Radix, or Min_length are outside the constraints.
- the #VALUE! error value if Number is a non-numeric value.
The largest value of the Min_length argument is 255.
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows calculation B3 converted to hard-coded value using the F9 key. The BASE function requires numerical values smaller than 2^53 which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
'BASE' function examples
Table of Contents How to use the DEC2BIN function How to use the DEC2HEX function How to use the DEC2OCT […]
Functions in 'Math and trigonometry' category
The BASE function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form