Skip to content
Advertisement

How to convert decimal format to number format

When I convert this binary to decimal:

010000010110110001101001001000000100000101101000011011010110010101100100001000000100111101110011011011010110000101101110001000000110001001101001011100100111010001101000011001000110000101110100011001010011101000110001001011010011001100101101001100010011100100111000001101110010000001100011011011110111010101101110011101000111001001111001001110100111001101110101011001000110000101101110

using VB.Net, I get this double number: 1.00695950340148E+115.

I need to format it to be normal number like this:

10069595034014783469636931351646363690636553221072125712116008033168565762469882090200055592025448896479090348155246

How can I do that using PHP or VB.Net?

Public Class Test
    Public Shared Sub Main()

Dim Bin as String = "010000010110110001101001001000000100000101101000011011010110010101100100001000000100111101110011011011010110000101101110001000000110001001101001011100100111010001101000011001000110000101110100011001010011101000110001001011010011001100101101001100010011100100111000001101110010000001100011011011110111010101101110011101000111001001111001001110100111001101110101011001000110000101101110"

Dim dec As Double = Nothing
Dim length As Integer = Len(Bin)
Dim temp As Integer = Nothing
Dim x As Integer = Nothing
        For x = 1 To length
            temp = Val(Mid(Bin, length, 1))
            length = length - 1
            If temp <> "0" Then
                dec += (2 ^ (x - 1))
            End If
        Next
        System.Console.WriteLine("Sum of x and y = " &  dec)
    End Sub
End Class

The output is:

Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.7 – tarball)
Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.
Assembly ‘jdoodle, Version=0.0, Culture=neutral, PublicKeyToken=null’ saved successfully to ‘/home/jdoodle.exe’. Compilation successful
Compilation took 00:00:01.1970230
Sum of x and y = 1.00695950340148E+115

Advertisement

Answer

please try with my this method, but I have not verified it whether it correct or not:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim myBin = "110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111110101010100001111101010101010101000000110110101100000010111"
    Debug.Print(ConvBinToDec(myBin))
End Sub

Function ConvBinToDec(ByVal theVal As String)
    ConvBinToDec = ""
    Dim BinVal(Len(theVal)) As String
    BinVal(1) = "1"
    Dim Total = "0"
    If Mid(theVal, Len(theVal), 1) = "1" Then Total = "1"
    Dim myLast As String = ""
    For a = 2 To Len(theVal)
        BinVal(a) = Multi(BinVal(a - 1))
        myLast = BinVal(a)
        If Mid(theVal, Len(theVal) - a + 1, 1) = "1" Then
            Total = Adding(Total, myLast)
        End If
    Next
    ConvBinToDec = Total

End Function

Function Multi(ByVal TheVal As String) As String
    Dim simpan As Byte = 0
    Multi = ""
    Dim myLen As Byte = 10
    Dim myTimes = -Int(-Len(TheVal) / myLen)

    For a = 1 To myTimes
        Dim myStr As String = Strings.Right(TheVal, a * myLen)
        Dim myRemain As String = Strings.Left(myStr, Len(myStr) - (a - 1) * myLen)
        Multi = Strings.Right("0000000000" & CLng(myRemain) * 2 + simpan, myLen) & Multi
        If Len(CStr(CLng(myRemain) * 2 + simpan)) > myLen Then simpan = 1 Else simpan = 0
        If a = myTimes And simpan = 1 Then Multi = "1" & Multi
    Next
End Function

Function Adding(ByVal TheVal1 As String, ByVal TheVal2 As String) As String
    Dim simpan As Byte = 0
    Adding = ""
    Dim myLen As Byte = 10
    Dim myTimes = -Int(-Len(TheVal2) / myLen)
    TheVal1 = Strings.Right("00000000000" & TheVal1, Len(TheVal2))
    For a = 1 To myTimes
        Dim myStr1 As String = Strings.Right(TheVal1, a * myLen)
        Dim myStr2 As String = Strings.Right(TheVal2, a * myLen)
        Dim myRemain1 As String = Strings.Left(myStr1, Len(myStr1) - (a - 1) * myLen)
        Dim myRemain2 As String = Strings.Left(myStr2, Len(myStr2) - (a - 1) * myLen)
        Adding = Strings.Right("0000000000" & CLng(myRemain1) + CLng(myRemain2) + simpan, myLen) & Adding
        If Len(CStr(CLng(myRemain1) + CLng(myRemain2) + simpan)) > myLen Then simpan = 1 Else simpan = 0
        If a = myTimes And simpan = 1 Then Adding = "1" & Adding
    Next
End Function

and when I tried to use your binary,

  "010000010110110001101001001000000100000101101000011011010110010101100100001000000100111101110011011011010110000101101110001000000110001001101001011100100111010001101000011001000110000101110100011001010011101000110001001011010011001100101101001100010011100100111000001101110010000001100011011011110111010101101110011101000111001001111001001110100111001101110101011001000110000101101110"

The Result is:

"000010069595034014783469636931351646363690636553221072125712116008033168565762469882090200055592025448896479090348155246"
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement