是否有任何大的整数类Visual Basic.net(128或更多位)? [英] Is there any big integer class for Visual Basic .NET (128 or more bits)?

查看:170
本文介绍了是否有任何大的整数类Visual Basic.net(128或更多位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以找到许多大整数库,但他们是所有的编程语言,除了VB.NET。有没有人知道一个类/库Visual Basic .NET可以处理非常大的数字? (我想处理1024或更多的位)。

Well I can find many big integer libraries but they are for all programming languages except VB.NET. Does anyone know a class/library for Visual Basic .NET which can handle very big numbers? (I'd like to handle 1024 or even more bits). The only calculation support I need it addition, substitution, multiplication, division and rounding.

需要使用这个代码:

Dim Letterz() As Integer = {33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0}
Function itoa(ByVal val As ULong)
    Dim toret As String = ""
    Dim TempVal As ULong = val
    For pos As ULong = 0 To 999999999999999999
        If TempVal > 0 Then
            Dim remainder As ULong = TempVal Mod Letterz.Length
            Dim ToInsert As Integer = Letterz(remainder)
            Dim ToInsStr As String = Chr(ToInsert)
            toret = ToInsStr & toret
            Dim DividedVal As Double = TempVal / Letterz.Length
            DividedVal = DividedVal - 0.5
            DividedVal = Math.Round(DividedVal, 0, MidpointRounding.ToEven)
            TempVal = DividedVal
        Else
            Exit For
        End If
    Next
    itoa = toret
End Function

Function atoi(ByVal val As String) As ULong
    Dim CURRNUM As ULong = 0
    Dim len As ULong = val.Length()
    If len > 0 Then
        For i As ULong = 0 To len - 1
            For x As ULong = 0 To Letterz.Length - 1
                Dim y As ULong = (len - i) - 1
                If val(y) = Chr(Letterz(x)) Then
                    Dim PWR As ULong = Math.Pow(Letterz.Length, i)
                    Dim MLTPLY As ULong = x * PWR
                    CURRNUM += MLTPLY
                End If
            Next
        Next
    End If
    atoi = CURRNUM
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    TextBox2.Text = itoa(ULong.Parse(TextBox1.Text))
    TextBox3.Text = atoi(TextBox2.Text).ToString()
End Sub


推荐答案

a href =http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx =nofollow> BigInteger 在中输入System.Numerics 。它可以用来表示一个任意大的有符号整数。

There is the BigInteger type in System.Numerics that was introduced in .NET 4. It can be used to represent "an arbitrarily large signed integer."

这篇关于是否有任何大的整数类Visual Basic.net(128或更多位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆