Sha256: 2f08481ce24e718368389df0b7aed56eab09c54194b4506221fb569ec6bc26c2

Contents?: true

Size: 705 Bytes

Versions: 396

Compression:

Stored size: 705 Bytes

Contents

Public Class Binary
    Private ReadOnly value As String

    Public Sub New(value As String)
        Me.value = value
    End Sub

    Public Function ToDecimal() As Integer
        If IsNotValidBinary() Then
            Return 0
        End If

        Return value.Select(Function(c, i) Integer.Parse(c.ToString()) * TwoToThePowerOf(value.Length - i - 1)).Sum()
    End Function

    Private Function IsNotValidBinary() As Boolean
        Return Not value.All(Function(x) Char.IsDigit(x) AndAlso Integer.Parse(x.ToString()) < 2)
    End Function

    Private Shared Function TwoToThePowerOf(power As Integer) As Integer
        Return CInt(Math.Truncate(Math.Pow(2, power)))
    End Function
End Class

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.4.0 tracks/vbnet/binary/Example.vb
trackler-2.0.3.9 tracks/vbnet/binary/Example.vb
trackler-2.0.3.8 tracks/vbnet/binary/Example.vb
trackler-2.0.3.7 tracks/vbnet/binary/Example.vb
trackler-2.0.3.6 tracks/vbnet/binary/Example.vb
trackler-2.0.3.5 tracks/vbnet/binary/Example.vb
trackler-2.0.3.4 tracks/vbnet/binary/Example.vb
trackler-2.0.3.3 tracks/vbnet/binary/Example.vb
trackler-2.0.3.2 tracks/vbnet/binary/Example.vb
trackler-2.0.3.1 tracks/vbnet/binary/Example.vb
trackler-2.0.3.0 tracks/vbnet/binary/Example.vb
trackler-2.0.2.0 tracks/vbnet/binary/Example.vb
trackler-2.0.1.2 tracks/vbnet/binary/Example.vb
trackler-2.0.1.1 tracks/vbnet/binary/Example.vb
trackler-2.0.1.0 tracks/vbnet/binary/Example.vb
trackler-2.0.0.10 tracks/vbnet/binary/Example.vb
trackler-2.0.0.9 tracks/vbnet/binary/Example.vb
trackler-2.0.0.8 tracks/vbnet/binary/Example.vb
trackler-2.0.0.7 tracks/vbnet/binary/Example.vb
trackler-2.0.0.6 tracks/vbnet/binary/Example.vb