C # in int transfer String 16 enrollment and 16 turn Double method

zhaozj2021-02-12  145

The 16-based 16-based 16-based 16 is not negative and decimal

#Region Change Hex To Double

Private Double HEXCONVERTODOUBLE (String HexString)

{

IF (HexString == "")

{

Return 0;

}

String data;

IF (HexString.StartSwith ("0x"))

{data = hexstring.substring (2);

Else

{data = hexstring;}

Char [] Eachdata = DATA.TOCHARRAY ();

Double result = 0;

For (int i = 0; i

{

Char Charvalue = Eachdata [I]; // Eachdata [M];

Double X = 16; // If it is an octal, write to 8. You can double y = system.convert.todouble (Eachdata.length - i - 1);

Switch (Charvalue)

{

Case '0':

Break;

CASE '1':

Result = 1 * Math.Pow (x, y);

Break;

Case '2':

Result = 2 * math.pow (x, y);

Break;

Case '3':

Result = 3 * Math.Pow (x, y);

Break;

Case '4':

Result = 4 * Math.Pow (x, y);

Break;

Case '5':

Result = 5 * Math.Pow (x, y);

Break;

Case '6':

Result = 6 * Math.Pow (x, y);

Break;

Case '7':

Result = 7 * math.pow (x, y);

Break;

Case '8':

Result = 8 * math.pow (x, y);

Break;

Case '9':

Result = 9 * math.pow (x, y);

Break;

Case 'a':

Result = 10 * math.pow (x, y);

Break;

Case 'b':

Result = 11 * math.pow (x, y);

Break;

Case 'C':

Result = 12 * Math.Pow (x, y);

Break;

Case 'd':

Result = 13 * math.pow (x, y);

Break;

Case 'E':

Result = 14 * Math.Pow (x, y);

Break;

Case 'f':

Result = 15 * math.pow (x, y);

Break;

Case 'a':

Result = 10 * math.pow (x, y);

Break;

Case 'b':

Result = 11 * math.pow (x, y);

Break;

Case 'C':

Result = 12 * Math.Pow (x, y); break;

Case 'd':

Result = 13 * math.pow (x, y);

Break;

Case 'E':

Result = 14 * Math.Pow (x, y);

Break;

Case 'f':

Result = 15 * math.pow (x, y);

Break;

DEFAULT:

Break;

}

Return Result;

}

#REGON Convert the int32 to hex // This method is very versatility, which can only be int 3 String 16

Private string specintostring (int source) // a auxiliary method called by the main method

{

IF (Source <10)

{

Return Source.toString ();

}

Else

{

Switch (Source)

{

Case 10:

Return "a";

Case 11:

Return "B";

Case 12:

Return "C";

Case 13:

Return "D";

Case 14:

Return "E";

Case 15:

Return "F";

DEFAULT:

""; "

}}}

Private string INTTOHEX (int Source) // main method

{

IF (Source <10)

{

Return "0x" Source.toString ();

}

Else IF (Source <= 15)

{

Return "0x" SpecintTostring (Source);

}

Else

{

INT raisenum = 16;

INT AddNum = 16;

INT positionnum = 1;

While (Source - Addnum)> = 0)

{POSITIONNUM ; addnum = addnum * raisenum;

int [] valuepositionnum = new int [positionnum];

For (int i = 0; i

{

ValuePositionNum [i] = 0;

int [] valueaddnum = new int [positionnum];

For (int i = 0; i

{

ValueAddnum [I] = Convert.Toint32 (Math.Pow (Raisenum, i));

int [] DecreaseSserve = new int rt [positionnum];

Decreasesource [PositionNum -1] = SOURCE

For (int i = positionnum -1; i> = 0; I -)

{

While ((DecreaseSserve "- ValueAddnum [i])> = 0)

{

IF (i! = 0)

DecreaseSOURCE [I -1] = DecreaseSource [i] - valueaddnum [i]; valuepositionnum [i] ; valueaddnum [i] = valueaddnum [i] convert.Toint32 (Math.Pow (raisenum, i));}} String [] stringvaluepositionnum = new string [positionnum];

For (int i = 0; i

{

StringvaluePositionNum [i] = specintostring (valuepositionnum [i]);

String result = "0x";

For (int i = positionnum -1; i> = 0; I -)

{Result = Result stringValuePositionNum [i];

Return Result;

// String [] hexlist = new string [positionnum 1];

// HEXLIST [POSITIONNUM] = SpecintToString (positionnum);

}

#ENDREGION #ENDREGION

转载请注明原文地址:https://www.9cbs.com/read-6359.html

New Post(0)