Bin2Dec

F

Francis Ang

I have searched the community website for VBA codes to convert binary code to
decimal but did not find any; although there are VBA codes for converting
decimal to binary codes.

Can anybody advise, where I can get hold of VBA codes for converting binary
code to decimal? I don't have the Analysis Tookpak.

Thank you.
 
J

JerryH

I'm just curious on how you would use this. Would you have a cell that has a
binary number in 1's and 0's and you want this converted to a decimal value?

Jerry
 
F

Francis Ang

Hi Jerry,

I have a file that contains some binary code which I need to convert to
decimals. I am also looking for codes that convert HEX2DEC. I know Excel has
these functions, but I don't have the Analysis Toolpack.
 
R

Rick Rothstein

Here is a VB function I've posted in the past that will handle up to a
96-bit binary number (which I'm guessing is way more than you will need)...

Function Bin2Dec(BinaryString As String) As Variant
Dim X As Integer
Const TwoToThe48 As Variant = 281474976710656#
For X = 0 To Len(BinaryString) - 1
If X > 48 Then
Bin2Dec = CDec(Bin2Dec) + Val(Mid(BinaryString, _
Len(BinaryString) - X, 1)) * _
TwoToThe48 * CDec(2 ^ (X - 48))
Else
Bin2Dec = CDec(Bin2Dec) + Val(Mid(BinaryString, _
Len(BinaryString) - X, 1)) * CDec(2 ^ X)
End If
Next
End Function
 

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