Home c# C #: from decimal to hexadecimal S.I

C #: from decimal to hexadecimal S.I

Author

Date

Category

Good day!

There is a row of numbers: 140000111111111 (only 16 characters) – decimal system.
I’m trying to convert to hexadecimal:

// Variant 1
  Return string.join (".", pin_block_encr.select (C = & GT; ((int) c) .tostring ("x2")));
  // Variant 2.
  var a = encoding.ascii.getbytes (pin_block_encr);
  var c = bitconverter.tostring (a);

(sample code)
The result of all ways that I tried the same – “

31.34.30.30.30.30.31.31.31.31.31.31.31.31.31.31.31.31.31.31


I decided to check with the help of an online translator (10 = & gt; 16) This, for example , and he gave me something completely different in my case:

4f94b28e9b5c7

The difference is obvious. And I’m more inclined to a 2nd version.

Tell me, please, as you can implement it on C #. Thank you.


Answer 1, Authority 100%

To begin with, get a number:

var n = long.parse ("140000111111111");

Over the way:

var hexstr = n.tostring ("x");

Long Instead of int , you need because your number in int does not fit.

Result : 4f94b28e9b5c7.


Answer 2, Authority 75%

uint64 val = 1400001111111111;
  Console.WriteLine (Val.Tostring (X ")); // C ~ Possibly Single-Digit Output
  Console.WriteLine (Val.Tostring (X2 ")); // 0C ~ Allways Double-Digit Output

Answer 3, Authority 25%

If it is known that the string consists of numbers, but the number of them is unknown, it makes sense to use the BigInteger class (it can be raised any line of numbers, within reasonable limits, of course).

var bi = biginteger.parse ("140000111111111");
var result = bi.tostring ("x");

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