java二进制转十六进制算法_java_十进制数转换为二进制,八进制,十六进制数的算法...

java Ê®½øÖÆÊýת»»Îª¶þ½øÖÆ,°Ë½øÖÆ,Ê®Áù½øÖÆÊýµÄË㕨

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 classForm1 : Form

{publicForm1()

{

InitializeComponent();

}//Ê®½øÖÆת¶þÖÆ

public string DtoB(intd)

{

string b= "";//ÅжϸÃÊýÈç¹ûСÓÚ2£¬ÔòÖ±½ÓÊä³ö

if (d < 2)

{

b=d.ToString();

}else{intc;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 ();

}

}returnb;

}//Ê®½øÖÆת°Ë½øÖÆ

public string DtoO(intd)

{

string o= "";if (d < 8)

{

o=d.ToString();

}else{intc;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];

}

}returno;

}//Ê®½øÖÆתʮÁù½øÖÆ

public string DtoX(intd)

{

string x= "";if (d < 16)

{

x=chang(d);

}else{intc;int s = 0;int n =d;int temp =d;while (n >= 16)

{

s++;

n= n / 16;

}

string [] m= newstring[s];int i = 0;do{

c= d / 16;

m[i++] = chang(d % 16);//ÅжÏÊÇ•ñ´óÓÚ10£¬Èç¹û´óÓÚ10£¬Ôòת»»ÎªA~FµÄ¸ñʽ

d =c;

}while (c >= 16);

x=chang(d);for (int j = m.Length - 1; j >= 0; j--)

{

x+=m[j];

}

}returnx;

}//ÅжÏÊÇ•ñΪ10~15Ö®¼äµÄÊý£¬Èç¹ûÊÇÔò½øÐÐת»»

public string chang(intd)

{

string x= "";switch(d)

{case 10:

x= "A";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;

}returnx;

}private voidbutton1_Click(object sender, EventArgs e)

{

textBox2.Text= DtoB(Convert.ToInt32(textBox1.Text));//ʮת¶þ½øÖÆ

}private voidbutton2_Click(object sender, EventArgs e)

{

textBox2.Text= DtoO(Convert.ToInt32(textBox1.Text));//ʮת°Ë½øÖÆ

}private voidbutton3_Click(object sender, EventArgs e)

{

textBox2.Text= DtoX(Convert.ToInt32(textBox1.Text));//ʮתʮÁù½øÖÆ

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值