(10转2;215除2,除到不能除为止,将余数倒记得1101 0111,)(10转16一般先10转成2,然后2转16就很方便,1101 0111,根据BCD码1101=DH,0111=7H,故的到16进制D7),(10转8,215%8,余数倒记得327)...
String changedData="" ; //字符串存放2进制数
int needConvertData = 215;
while( needConvertData >= 2 )
{
changedData = (needConvertData % 2).ToString() + changedData;
needConvertData /= 2;
}
changedData= needConvertData+changedData ;
输出 changeddata=11010111
String changedData="" ; //字符串存放8进制数
int needConvertData = 215;
while( needConvertData >= 8 )
{
changedData = (needConvertData % 8).ToString() + changedData;
needConvertData /=8;
}
changedData= needConvertData+changedData ;
输出 changeddata=327
String changedData="" ; //字符串存放16进制数
int needConvertData = 215;
String temp16chr="";
while( needConvertData >= 16 )
{
if (needConvertData % 16==10)
temp16chr="A";
else if (needConvertData % 16==11)
temp16chr="B";
else if (needConvertData % 16==12)
temp16chr="C";
else if (needConvertData % 16==13)
temp16chr="D";
else if (needConvertData % 16==14)
temp16chr="E";
else if (needConvertData % 16==15)
temp16chr="E";
else
temp16chr=(needConvertData % 16).Tostring();
changedData =temp16chr + changedData;
needConvertData /=16;
}
changedData= needConvertData+changedData ;
输出 changeddata=137