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).
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.
'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 61 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