-1

How are you?

In order to make the program I am working on more user-friendly and easier to deploy on Windows machines, I am in the process of converting an algorithm from Python (which works wonders) to VB .NET.

In this order:
-> Fetching decimal from data sheets (Excel, CSV, XML...)
-> Conversion to binary (string)
-> Binary manipulation / appending
-> Inversion (first char becomes last)
-> Conversion to signed integer for additional math
-> Final conversion to Hexadecimal (targeting a car ECU implementation)

However, this algorithm does huge number conversions (we are talking 1.0E100+), and while everything is done seamlessly in Python thanks to the variables auto assignment, etc., I can't seem to manipulate them on VB .NET due to their size, causing OverflowExceptions all the time.

So far, I know the biggest variables available in VB .NET are Decimal and UInt64, but they definitely don't suit my needs.

I also know that I can bypass the OverflowException checking in Visual Studio, but what would be the downsides? What leads/ideas/solutions would you suggest me? Is there any way to manipulate these kinds of numbers just like I did in Python?

Thank you very much!

user7831458
  • 83
  • 1
  • 8
  • "available in VB .NET are Decimal and UInt64", what type are you using instead? – Caramiriel May 04 '17 at 10:32
  • Use the `BigInteger` structure. It is not a native VB data type and is a member of the `System.Numerics` namespace rather than `System`. – jmcilhinney May 04 '17 at 11:19
  • That's what I'm using, but I get OverflowExceptions nonetheless when using functions like Convert.ToInt64, or even making my own functions converting Binary to Decimal. There isn't any variable type I can use to contain my numbers... – user7831458 May 04 '17 at 11:19
  • by "car ECU" do you mean CAN-bus? Can you show a sample of the data from your data sheets? – David Sdot May 04 '17 at 11:20
  • David: kind of. My ECU has an embedded software, and I'm basically making a software auto calculating some parameters that I will afterwards send it through CAN. The sent data is just random, lengthy hex numbers like 76576AB77AAA86733H54567890BFFF... But have critical signification. – user7831458 May 04 '17 at 12:53

1 Answers1

0

A BigInteger can hold a number as large as how much memory your application can allocate. Thus the more memory your application is able to allocate, the larger number the structure can hold.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
  • Oh wow! Thank you so much! But unfortunately I can't seem to import the class to my project. Is it in truly in System.Numerics? Because Visual Studio can't seem to find it (I have .NET 4.6). Thanks again! – user7831458 May 04 '17 at 12:50
  • 1
    Answering to myself: you must add it as a reference through Visual Studio in the menu Project > Add Reference > Assemblys > Framework > System.Numerics. Thanks again! – user7831458 May 04 '17 at 12:58
  • @user7831458 : You ought to do the same for any old, answered questions as well. :) – Visual Vincent May 04 '17 at 13:13