十进制转化成十六进制:
void In_to_a16(int ix){
long iy=0;
int a1=0;
a1=(ix&0x000000FF);//提取最高位字节
int a2=0;
a2=(ix&0x0000FF00)>>8;
int a3=0;
a3=(ix&0x00FF0000)>>16;
int a4=0;
a4=(ix&0xFF000000)>>24; //提取最低位字节
char buffer[10];
sprintf(buffer,"%.2X%.2X%.2X%.2X",a4,a3,a2,a1);
printf("%s",buffer);
}
十进制转化成2进制:
void In_to_a2(int ix){
char a[64];
int i=0;
while(ix){
//cout<<"ix="<<ix<<endl;
if(ix&1){
a[i]='1';
i++;
ix=ix>>1;
}else{
a[i]='0';
i++;
ix=ix>>1;
}
}
for(int k=0;k<i;k++){
printf("%c",a[k]);
}
}