Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Namespace exdtob
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
// Convert decimal to binary
Public String dtob (int d)
{
String B = "";
// Determine if the number is smaller than 2, then the output is directly
If (d <2)
{
B = D. tostring ();
}
Else
{
Int C;
Int S = 0;
Int n = D;
While (n> = 2)
{
S ++;
N = n/2;
}
Int [] M = new int [s];
Int I = 0;
Do
{
C = D/2;
M [I ++] = D % 2;
D = C;
} While (C> = 2 );
B = D. tostring ();
For (Int J = M. Length-1; j> = 0; j --)
{
B + = m [J]. tostring ();
}
}
Return B;
}
// Convert decimal to octal
Public String dtoo (int d)
{
String o = "";
If (d <8)
{
O = D. tostring ();
}
Else
{
Int C;
Int S = 0;
Int n = D;
Int temp = D;
While (n> = 8)
{
S ++;
N = N/8;
}
Int [] M = new int [s];
Int I = 0;
Do
{
C = D/8;
M [I ++] = D % 8;
D = C;
} While (C> = 8 );
O = D. tostring ();
For (Int J = M. Length-1; j> = 0; j --)
{
O + = m [J];
}
}
Return O;
}
// Convert decimal to hexadecimal
Public String dtox (int d)
{
String x = "";
If (d <16)
{
X = Chang (d );
}
Else
{
Int C;
Int S = 0;
Int n = D;
Int temp = D;
While (n> = 16)
{
S ++;
N = N/16;
}
String [] M = new string [s];
Int I = 0;
Do
{
C = D/16;
M [I ++] = Chang (d % 16); // determines whether the value is greater than 10. If the value is greater than 10, it is converted to ~ F format
D = C;
} While (C> = 16 );
X = Chang (d );
For (Int J = M. Length-1; j> = 0; j --)
{
X + = m [J];
}
}
Return X;
}
// Judge whether the value is 10 ~ The number between 15. If yes, the conversion is performed.
Public String Chang (int d)
{
String x = "";
Switch (d)
{
Case 10:
X = "";
Break;
Case 11:
X = "B ";
Break;
Case 12:
X = "C ";
Break;
Case 13:
X = "D ";
Break;
Case 14:
X = "E ";
Break;
Case 15:
X = "F ";
Break;
Default:
X = D. tostring ();
Break;
}
Return X;
}
Private void button#click (Object sender, eventargs E)
{
Textbox2.text = dtob (convert. toint32 (textbox1.text); // convert 10 to binary
}
Private void button2_click (Object sender, eventargs E)
{
Textbox2.text = dtoo (convert. toint32 (textbox1.text); // 10 to 8 bytes
}
Private void button3_click (Object sender, eventargs E)
{
Textbox2.text = dtox (convert. toint32 (textbox1.text); // convert to hexadecimal
}
}
}