Macro converting bin to dec

S

Sasa

I was thinking about this problem and I need some help. Im
trying to make macro which will convert some binary
numbers into decimal numbers. The page looks like this:

0 0 0 0 0 1 1 0
0 0 0 0 1 0 0 1
0 1 0 0 0 0 0 1
0 0 0 1 0 0 1 1
0 0 0 1 0 1 0 1
etc.

And what I want is to convert all of the binary numbers
into decimal like:

6
9
65
19
21
etc.

Do you have any ideas?
Thank you for your help.
Regards.

Sasa
 
H

Helmut Weber

Hi Sasa,
assuming, that you have got strings,
representing 8 digit binary numbers:
Function Bin2Dec(B As String) As Integer
Dim i As Integer
Dim n As Integer
Dim D As String
For i = 1 To 15
If IsNumeric(Mid(B, i, 1)) Then
D = D + Mid(B, i, 1)
End If
Next
For i = 1 To 8
n = n + CInt(Mid(D, i, 1)) * 2 ^ (8 - i)
Next
Bin2Dec = n
End Function

Sub test333()
MsgBox Bin2Dec("0 0 0 0 0 0 1 1")
End Sub

Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 

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