E
E Avila Q
Guest
Dear Sirs.
I have a problem to perfom multiplication with two Bigiinteger(Byte[]) instantiated numbers. Althoug I have used all the methods to create a byte array from a numeric string, the operation gives me wrong results.
I have used successfully the BigInteger.Parse method. The problem is that it is very slow, due to the fact that I use very big numbers.
As per the early exposed, I wrote the attached code. I would like to receive some help. I would be very pleased to know where I am failing. By the way, the expected answer should be received in the variable named 'Product'.
Thanks in advance by your help
Edgar Avila
Dim Final_Multiplicand As String = "9791276516423086698023068732872876872254768957476975497354975469754748266484056"
Dim Final_Multiplier As String = "7845086043289856973486438598768975583428624385280968945768432602036897645897652897"
Dim Multiplied As BigInteger
Dim MultiplicandByte() As Byte
Dim MultiplierByte() As Byte
Dim Product As String
Dim MultipliedToString() As Byte
Dim MultipliedToByte() As Byte
MultiplicandByte = StringToByte(Final_Multiplicand)
MultiplierByte = StringToByte(Final_Multiplier)
Multiplied = BigInteger.Multiply(New BigInteger(MultiplicandByte), New BigInteger(MultiplierByte))
MultipliedToByte = Multiplied.ToByteArray
Product = ByteToString(MultipliedToByte)
Public Shared Function StringToByte(SentString As String) As Byte()
Dim IntegerList As List(Of Integer)
Dim IntegerArray() As Integer
Dim IntegerByte() As Byte
IntegerList = SentString.[Select](Function(character) Integer.Parse(character.ToString())).ToList()
IntegerArray = Array.ConvertAll(IntegerList.ToArray(), Function(o) Convert.ToInt32(o))
IntegerByte = IntegerArray.[Select](Function(i) CByte(i)).ToArray()
Return IntegerByte
End Function
Public Shared Function ByteToString(SentByte() As Byte) As String
Dim Converted As String
Dim IntegerArray As Integer()
IntegerArray = Array.ConvertAll(SentByte.ToArray(), Function(o) Convert.ToInt32(o))
Converted = String.Join("", IntegerArray.[Select](Function(p) p.ToString()).ToArray())
Return Converted
End Function
Continue reading...
I have a problem to perfom multiplication with two Bigiinteger(Byte[]) instantiated numbers. Althoug I have used all the methods to create a byte array from a numeric string, the operation gives me wrong results.
I have used successfully the BigInteger.Parse method. The problem is that it is very slow, due to the fact that I use very big numbers.
As per the early exposed, I wrote the attached code. I would like to receive some help. I would be very pleased to know where I am failing. By the way, the expected answer should be received in the variable named 'Product'.
Thanks in advance by your help
Edgar Avila
Dim Final_Multiplicand As String = "9791276516423086698023068732872876872254768957476975497354975469754748266484056"
Dim Final_Multiplier As String = "7845086043289856973486438598768975583428624385280968945768432602036897645897652897"
Dim Multiplied As BigInteger
Dim MultiplicandByte() As Byte
Dim MultiplierByte() As Byte
Dim Product As String
Dim MultipliedToString() As Byte
Dim MultipliedToByte() As Byte
MultiplicandByte = StringToByte(Final_Multiplicand)
MultiplierByte = StringToByte(Final_Multiplier)
Multiplied = BigInteger.Multiply(New BigInteger(MultiplicandByte), New BigInteger(MultiplierByte))
MultipliedToByte = Multiplied.ToByteArray
Product = ByteToString(MultipliedToByte)
Public Shared Function StringToByte(SentString As String) As Byte()
Dim IntegerList As List(Of Integer)
Dim IntegerArray() As Integer
Dim IntegerByte() As Byte
IntegerList = SentString.[Select](Function(character) Integer.Parse(character.ToString())).ToList()
IntegerArray = Array.ConvertAll(IntegerList.ToArray(), Function(o) Convert.ToInt32(o))
IntegerByte = IntegerArray.[Select](Function(i) CByte(i)).ToArray()
Return IntegerByte
End Function
Public Shared Function ByteToString(SentByte() As Byte) As String
Dim Converted As String
Dim IntegerArray As Integer()
IntegerArray = Array.ConvertAll(SentByte.ToArray(), Function(o) Convert.ToInt32(o))
Converted = String.Join("", IntegerArray.[Select](Function(p) p.ToString()).ToArray())
Return Converted
End Function
Continue reading...