ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How can I convert binary numbers to decimal when they are larger . (https://www.excelbanter.com/excel-worksheet-functions/22037-how-can-i-convert-binary-numbers-decimal-when-they-larger.html)

Nebulae

How can I convert binary numbers to decimal when they are larger .
 
I am using Excel (MS Office 2003) with the Analysis ToolPak installed. The
function BIN2DEC (and the other related functions) work fine with small
numbers, but give the #NUM display when the value is greater than 10 places.
The help file states that the maximum number of places is 10. Are there any
other functions or any add ins that will handle larger numbers?

JE McGimpsey

One way (using a UDF):

Public Function LongBinToDec( _
Optional ByVal sInput As String = "") As Variant
Dim dTemp As Double
Dim i As Long
sInput = Application.Substitute(sInput, " ", "")
If sInput Like "*[!01]*" Then
LongBinToDec = CVErr(xlErrValue)
Else
For i = 1 To Len(sInput)
dTemp = dTemp * 2 + Mid(sInput, i, 1)
Next i
LongBinToDec = dTemp
End If
End Function

If you're unfamiliar with UDFs, see David McRitchie's "Getting Started
with Macros and User Defined Functions":

http://www.mvps.org/dmcritchie/excel/getstarted.htm

In article ,
"Nebulae" wrote:

I am using Excel (MS Office 2003) with the Analysis ToolPak installed. The
function BIN2DEC (and the other related functions) work fine with small
numbers, but give the #NUM display when the value is greater than 10 places.
The help file states that the maximum number of places is 10. Are there any
other functions or any add ins that will handle larger numbers?



All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com