十转二,八,十六
#include<stdio.h>
int main()
{
int a,b=1,c=0,d,e,f,g,h;
printf("十进制\t二进制数\t八进制\t\t十六进制\n");
for(a=1;a<=256;a++){
printf("%d\t",a);
while(a>=b){
b=b*2;
c++;
}
b=b/2;
e=a;
while(c>0){
d=e/b;
printf("%d",d);
e=e%b;
b=b/2;
c--;
}
printf("\t\t");
b=1;
while(a>=b){
b=b*8;
c++;
}
b=b/8;
f=a;
while(c>0){
d=f/b;
printf("%d",d);
f=f%b;
b=b/8;
c--;
}
printf("\t\t");
b=1;
while(a>=b){
b=b*16;
c++;
}
b=b/16;
g=a;
while(c>0){
d=g/b;
h=d;
switch(h){
case 10: h='A'; printf("%c",h); break;
case 11: h='B'; printf("%c",h); break;
case 12: h='C'; printf("%c",h); break;
case 13: h='D'; printf("%c",h); break;
case 14: h='E'; printf("%c",h); break;
case 15: h='F'; printf("%c",h); break;
default:
printf("%d",d);
}
g=g%b;
b=b/16;
c--;
}
printf("\n");
b=1;
}
return 0;
}