Home c# Translation from the 16-riche system C #

Translation from the 16-riche system C #




The input (in particular to textbox) is given a 16-riche number with which you need to perform certain mathematical actions. I assume that it is necessary to convert to the 10rd system to implement.
The essence of the problem is as follows:
1. How to realize fool protection in a specific one?
2. How to convert a number in a 10-way? You can use PARSE, however, can it convert a 16-riche number with a point?

Well, as a conclusion, maybe I see a question not under the angle and there are solutions easier and more rational?

Answer 1, Authority 100%

Well, this way can be translated into a 10-key number system

int x = convert.toint32 (textbox1.text, 16);

For a number with a point, you can try to translate in parts, first the whole part, then fractional. And then record in Double

1 Option:

And about protecting from fools, it may be worth trying the text to textbox not immediately, but the keys read and the keys were read with valid characters.

key [] validkeys = {key.d1, key.d2, ..., key.numpad1, key. NUMPAD2, ..., Key.a, Key.b, ..., Key.f}

And then the button is pressed compared with this array. And only then the symbol was added to the line.

Option 2:

Create a keystroke event on a key that will compare the changed line with the initial one. And if the symbol on which it has changed is not included in the range of validates, then assign the original string.

Answer 2

about the point, you can use something like this.

string [] hexarray = textbox.text.split ('.' ');
// If the number has a fractional and whole part, then the array will be 2 long.
if (hexarray.length == 2)
  // Convert to 10tic.
  String TMP = convert.TOINT32 (Hexarray [0], 16) .tostring () + "," + convert.toint32 (Hexarray, 16) .tostring ();
  // Transform the Double string.
  converttodouble = convert.todouble (TMP);
  // Otherwise, if the separator was not and the number is an integer, then simply convert the number.
  String TMP = Convert.TOINT32 (Hexarray [0], 16) .tostring ();
  converttodouble = convert.todouble (TMP);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions