Mega Code Archive

 
Categories / VB.Net / Data Types
 

Convert BigInteger to Byte Array back and forth

Imports System Imports System.Text Imports Microsoft.VisualBasic.Strings Imports System.Numerics Class MainClass     Public Shared Sub Main()       Dim positiveValue As BigInteger = BigInteger.Parse("123123123123123123123")       Dim negativeValue As BigInteger = BigInteger.Add(Int64.MaxValue, 60000)        Dim positiveValue2, negativeValue2 As BigInteger              Dim positiveBytes() As Byte = positiveValue.ToByteArray()       Dim negativeBytes() As Byte = negativeValue.ToByteArray()              negativeValue2 = New BigInteger(negativeBytes)       Console.WriteLine("Converted the byte array to {0:N0}", negativeValue2)       positiveValue2 = New BigInteger(positiveBytes)       Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2)     End Sub End Class