Convert a number upto 100 to binary

G

Guest

Has anybody got a piece of code that can convert a nuber in a cell, say A1
and display it as a 7 digit binary number in B1?
I have tried to do this working from the 7th digit backwards using
combinations of 'if' and 'and' functions, but by the time I get to the 5/4
digits I am losing the will to live!

Many thanks in advance
 
B

Bob Phillips

=DEC2BIN(A21)

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

WOW thanks for the quick response.

Tried this but get a #NAME? error.

Is there an add on or a definition I need to make this work?
 
N

NickHK

Mark,
You need the Analysis Tool pack add-in installed.

Or you can make your own version. This seems to work:

Public Function MyDec2Bin(DecIn As Long, Optional MaxBin As Long = 7) As
String
Dim TempStr As String
Dim i As Long

Do Until Len(TempStr) = MaxBin
If (DecIn And 2 ^ i) = 2 ^ i Then
TempStr = "1" & TempStr
Else
TempStr = "0" & TempStr
End If
i = i + 1
Loop

MyDec2Bin = TempStr

End Function

NickHK
 

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