Question

I am programming on a project which I should store the key of the user to the initial configuration of a machine, I want to write it in C#.

I have an initial configuration which consists of two number R and X0, R = 3.9988 and X0 = 0.5. I want to add the user key to these numbers. for example:

Key: hos110 =>

  • R = 3.9988104111115049049048
  • X0 = 0.5104111115049049048

104111115049049048 are ASCII codes of the key which are concatenated.

How can I store these numbers?

Is there a better method for doing this?

Update: How about MATLAB?

Was it helpful?

Solution

If you need infinite precision you need something that is called BigInteger. However these classes are usually only used for scientific calculations (and usually unsuited for stroring the data) which doesn't really seem to match your code sample. If you need to do only general calculations use Strings and then convert them to Decimal for the calculations.

However if you are looking for such a BigInterger Class you can find one here.

.Net 4.0 will have a BigInteger built-in-class in the class libraries named System.Numerics.BigInteger.

OTHER TIPS

You're not really "adding" numbers. You are concatenating strings.

Store them as strings. You can't get much more precise than that.

If you need to perform any arithmetic operations, it is easy enough to convert them to a decimal number on the fly.

I don't really follow why you're using a key as part of a number, but leaving that aside... System.Decimal (aka decimal) seems like the right tool for the job here.

Well, depending on the precision you are trying to achieve, you can probably save these as a pair of decimal values.

However, if this is an ASCII code, you may just want to save these as a string directly. This will avoid the numerical precision issues, especially if you're going to pull off the 104111... prior to using this information.

It seems that you are storing a "key", so why not use a String then?

Floating point numbers are inherently imprecise. I'm not sure what this 'initial configuration' is or why it's a float, but you're not going to be able to tack on a 'user key' (whatever that may be) and recover it later. Store the user key separately, in a string or something.

If these 'numbers' have no numeric value, i.e. you will not use them for mathematical computation then there is no need to store them in a numeric datatype. You can store them as strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top