DEC2BIN Function for numbers to 80,000??

T

Tom M

The function in Excel 2000 only converts to 10 digits
(bits) or 511 decimal. Anyone know how to increase the
range up to 80,000 or 100,000 ?? or up to 32 bits thanks
 
J

Jerry W. Lewis

Here is brute force approach to convert up to 10 decimal digits to
binary. You could modify it to a specific word size to handle negative
numbers.

Function D2B(ByVal n As Long) As String
n = Abs(n)
D2B = ""
Do While n > 0
If n = (n \ 2) * 2 Then
D2B = "0" & D2B
Else
D2B = "1" & D2B
n = n - 1
End If
n = n / 2
Loop
End Function

Jerry
 
J

J.E. McGimpsey

One way:

for 32 bits:

=DEC2BIN(A1/512^3,5) & DEC2BIN(INT(MOD(A1,512^3)/512^2),9) &
DEC2BIN(INT(MOD(A1,512^2)/512),9) & DEC2BIN(MOD(A1,512),9)


Note: 32 bits represents 2^32-1 or 4,294,967,295 which is
significantly larger than 80,000 or 100,000

To cover 80,000 (or 100,000) only requires 17 bits:

=DEC2BIN(A1/512,8)&DEC2BIN(MOD(A1,512),9)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top