c中unsigned int 转换成unsigned char类型

void fu(unsigned int n){

	int k,k1;
	k=n/16;
	k1=n%16;
	if(k<=15){
		switch(k1){
	case 10: temp = 0xa0; break;
		case 11: temp = 0xb0; break;
		case 12: temp = 0xc0; break;
		case 13: temp = 0xd0; break;
		case 14: temp = 0xe0; break;
		case 15: temp = 0xf0; break;
		default: temp = k << 4;
		 
	}
	}
	if(k1<=15){
		switch(k){
		case 10: temp = temp + 0x0a; break;
		case 11: temp = temp + 0x0b; break;
		case 12: temp = temp + 0x0c; break;
		case 13: temp = temp + 0x0d; break;
		case 14: temp = temp + 0x0e; break;
		case 15: temp = temp + 0x0f; break;
		default: temp = temp + k1; 
		 
	}
	}
	
}
posted @ 2020-09-02 15:28  jee-cai  阅读(753)  评论(0编辑  收藏  举报