I am very new to VB.Net and as a first project I am trying to build a calculator similar to the windows scientific calculator. I have a specific problem when I try to convert a binary Qword to decimal. I am using this loop:
PublicFunction BTD(ByVal Bin AsString) As String
Dim i AsInteger
Dim Dec As Long
For i = Bin.Length To 1 Step -1
If Mid(Bin, i, 1) And 1 Then
Dec = Dec + 2 ^ (Bin.Length - i)
EndIf
Next i
keyData = Dec
EndFunction
Using the Long Data Type I get an Arithmetic Overflow Exception and if I use the String Data Type the result for DEC is in scientific notation (xx+Exx) with this as a value I dont know how to translate it back to a numeral that can be used in converting to another base (say the user wants to convert the value to hex after converting from binary to decimal). So my question is how do I handle large numbers like this?
i.e:
If the original Binary Qword value is equivalent to 2^64 the decimal number would be "18446744073709551616" which is too large for the Long Data Type.
Is the loop I am using correct for this situation(It works for Dword values) or should I rethink the approach as a whole?
Note The windows calculator handles these correctly If someone knows how its done in the windows calc please let me know. I am just starting out with VB.Net so any guidenece will be appreciated.
PublicFunction BTD(ByVal Bin AsString) As String
Dim i AsInteger
Dim Dec As Long
For i = Bin.Length To 1 Step -1
If Mid(Bin, i, 1) And 1 Then
Dec = Dec + 2 ^ (Bin.Length - i)
EndIf
Next i
keyData = Dec
EndFunction
Using the Long Data Type I get an Arithmetic Overflow Exception and if I use the String Data Type the result for DEC is in scientific notation (xx+Exx) with this as a value I dont know how to translate it back to a numeral that can be used in converting to another base (say the user wants to convert the value to hex after converting from binary to decimal). So my question is how do I handle large numbers like this?
i.e:
If the original Binary Qword value is equivalent to 2^64 the decimal number would be "18446744073709551616" which is too large for the Long Data Type.
Is the loop I am using correct for this situation(It works for Dword values) or should I rethink the approach as a whole?
Note The windows calculator handles these correctly If someone knows how its done in the windows calc please let me know. I am just starting out with VB.Net so any guidenece will be appreciated.