输入正整数(0~255),将其转换为一个8位的二进制数,或将...1
发布网友
发布时间:2023-11-03 17:39
我来回答
共1个回答
热心网友
时间:2024-09-18 15:41
void TenToBinary(unsigned char cN)
{
unsigned char cTmp = cN;
for (int i=sizeof(unsigned char)*8-1; i>=0; i--)
{
putchar ( '0' + ((unsigned)(cTmp & (1<<i))>>i) );
}
}
void main()
{
int iN;
cout<<"Please Input a value:";
cin>>iN;
TenToBinary((unsigned char )iN);
cout<<endl;
}