# Convert decimal to binary excel formula

Then I ran into a little problem with certain numbers. Eight in binary is In that situation, can I just add one digit ? Does the user of the output have to know how many bits in order to interpret the output correctly? At least I know what to expect, though. So I made the output a multiple of four which allows for some predictability, but there are still problems.

In this case, I need to add more bits to make the negative meaningful, but I don't have to do it for, say, 2 and -2 and or do I? So the question is: How many bits do I show and how do I determine that? I came to your page googling for something else, but liked your page, and read through it. In your example of 2 and -2 and , there IS room for misinterpretation, since 14 is also and is That means your 4 bit binaries have a maximum value of 7 You currently show 8 as which is incorrect under this rule.

You should show 8 as , or if you are using multiples of 4 bits. Remember the good old days of Z80 8 bit processors? Where forcen creates a binary of length n, if the user selects this. Otherwise, it would use your automatic multiple of 4 rule, including my previous comments. For negative numbers, it is quicker to take the abs decimal, subtract one, do the binary, then NOT the result. This way it is ok to return 2nd complement for a negative number, but it assumes integer format.

Ok- Please summarize this dicussion for me. I am not a VB programmer. Copy and paste it into an excel macro. A2 should now include the binary number. The following function can be used to convert from base 10 decimal to base 2 binary.

It is implemented to return a number which results in a loss of leading zeros but the result cell can easily be formatted to display as many leading zeros as required by setting a custom format e.

While this function which works fine as a UDF only handles positive values, it will return the Binary string for values up to If the value you want to process is larger than Excel can properly handle as whole number, simply pass the value in as text. So, for the maximum value the function can handle, you would call it like this from VB…. Either base can be anything from 2 to To undertake this activity there is an expectation that students have an understanding of binary numbers and how to count in binary.

Refer to the introduction to binary lesson. Use the following table with headings to show the progression of the binary numeral system much like 1s, 10, , for decimal system. Binary is a doubling pattern of 1, 2, 4, 8, 16 etc.

Use the table to ensure all students can count in binary and represent decimal numbers in binary. Note remember to start from the left when using the table to make a decimal number.

For example to make the number 31 do I need a 16, YES. Do I need and 8, NO. Do I need a 4, YES. Do I need a 2, NO. Do I need a 1, YES. So the binary number is Repeat this process for other numbers. Try making numbers Ask what the largest number than can be made in this table.

How can we make the number ? Discuss the pattern of doubling to get 64 and and add these two new columns.