How to use the DEC2BIN function
The DEC2BIN function converts a decimal number to a binary number.
What is a decimal number?
The decimal system is a positional numeral system that uses 10 as the base, it requires 10 different numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The dot or the decimal point represents decimal fractions which are not whole numbers.
The decimal number 520 has three positions, each with a different weight. It starts with 10^0 on the right and increases by one power on each additional position to the left.
520 = (5*10^2)+(2*10^1)+(0*10^0)
520 = 500 + 20 + 0
What is a binary number?
The binary system is a positional numeral system that uses only two digits: 0 and 1. The binary system is important in our society, many devices like computers, digital cameras, mobile phones and modern cars use binary code to store, process and communicate data. The binary numeral system makes it easy to store and transmit data using binary digits or bits.
Decimal | Binary |
0 | 0 |
1 | 1 |
2 | 10 |
3 | 11 |
4 | 100 |
5 | 101 |
6 | 110 |
7 | 111 |
8 | 1000 |
9 | 1001 |
10 | 1010 |
11 | 1011 |
12 | 1100 |
13 | 1101 |
14 | 1110 |
15 | 1111 |
16 | 10000 |
Table of Contents
1. DEC2BIN function Syntax
DEC2BIN(number, [places])
2. DEC2BIN function Arguments
number | Required. The decimal integer you want to convert. The sign bit is the most significant bit of number, the following 9 bits are magnitude bits. Negative numbers are represented using two's-complement notation. Maximum binary values are 10 characters. |
[places] | Optional. The number of characters to use. If not entered the function uses the number of characters needed to complete the task. This argument allows you to add leading 0s (zeros). |
What is a sign bit?
The sign bit indicates whether a binary number is positive or negative, if the bit is 0 the number is positive, if the bit is 1, the number is negative.
What is a magnitude bit?
The remaining 9 bits are magnitude bits which represents the absolute value of the number. An absolute number is a number without the sign.
What is two's-complement notation?
Two’s-complement notation is used to represent negative numbers, the magnitude bits are changed from 0 to 1 and 1 to 0 and adding 1 to the result. For example:
Decimal number +9 using 10 bits is 0000001001.
Decimal number -9 using 10 bits is 1111110110 + 1 = 1111110111
3. DEC2BIN function example
The image above shows the DEC2BIN function in cells D3 an D4. It calculates the binary values based on the corresponding cells which contain different decimal numbers.
Formula in cell D3:
The first cell B3 contains 9 and cell C3 contains the places number, the DEC2BIN function returns 00001001 in cell D3, the second cell B4 contains 2 and the DEC2BIN function returns 00000010 in cell D4.
The next section describes how these values are calculated in detail.
4. How is the DEC2BIN function calculated in detail?
Follow these steps to convert from decimal to binary:
- Divide the decimal number by 2 and write down the quotient and the remainder.
- Repeat the process with the quotient until it is zero. Make sure to note each quotient and remainder as you calculate each number.
- The binary number is the remainders from bottom to top.
For example, let us convert decimal number 199 to binary.
199/2 = 99 and remainder 1
99/2 = 49 and remainder 1
49/2 = 24 and remainder 1
24/2 = 12 and remainder 0
12/2 = 6 and remainder 0
6/2 = 3 and remainder 0
3/2 = 1 and remainder 1
1/2 = 0 and remainder 1
The binary number is 11000111 counting from bottom to top.
5. DEC2BIN Function error
DEC2BIN returns the #NUM! error value if
- Less than -512 or larger than 511. See cells B3 and C3 in the image above.
- [places] is negative. See the formula next to cell C5.
- it requires more than the specified places characters. See the formula next to cell C4.
DEC2BIN returns the #VALUE! error if
- places is not a number. See the formula next to cell C7.
- The number is not a valid base 10 number. See cells B4 and C4 in the image above.
The second argument [places]is truncated if it is not an integer. For example, [places] is 4.1111111111 and the DEC2BIN function truncates it to 4. See the formula next to cell C8.
DEC2BIN ignores places and returns a 10-character binary number if the decimal number is negative.
6. How to convert large decimal numbers to binary?
The following formula converts numbers larger than 511 to their binary representation, it works only for positive decimal numbers. This is a workaround for the DEC2BIN function which has a limit of decimal numbers larger than 511.
Formula in cell C5:
This formula converts the number in cell B5 to its binary representation and returns it as a text string. Cell B5 contains 512 and the result is 1000000000
The BASE function converts a number into a text representation with a given radix (base).
Function syntax: BASE(number, radix, [min_length])
DEC2BIN function - Microsoft
Decimal to Binary converter
Decimal to Binary
'' function examples
Table of Contents How to use the DEC2BIN function How to use the DEC2HEX function How to use the DEC2OCT […]
What's on this page Reverse text Insert random characters Convert letters to numbers How to shuffle characters in the alphabet […]
Functions in 'Engineering' category
The DEC2BIN function function is one of 42 functions in the 'Engineering' 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