#include <stdio.h>
int main()
{
int num, mask;
int count = 0;
int i;
char str[20];
PRintf("Please input a number:/n");
scanf("%d", &num);
mask = 1 << 7;
for(i = 0; i < 8; i++)
{
if((num & mask ? '1' : '0') == '1')
{
count++;
str[i] = 1;
}
else
{
str[i] = 0;
}
num <<= 1;
}
printf("the number is:");
for(i = 0; i < 8; i++)
{
printf("%d", str[i]);
}
printf("/n");
printf("the number of one is %d./n", count);
return 0;
}
#include <stdio.h>
int main()
{
int num, mask;
int p1, p2;
int i = 0;
int j;
char str[50];
printf("Please input a number:/n");
scanf("%d", &num);
printf("Please input p1 p2(<32):/n");
scanf("%d %d", &p1, &p2);
mask = 1 << (p2 - 1);
while(p2 >= p1)
{
if((num & mask ? '1' : '0') == '1')
{
str[i++] = '1';
p2--;
num <<= 1;
}
else
{
str[i++] = '0';
p2--;
num <<= 1;
}
}
printf("the binary system is:");
for(j = i-1; j >= 0; j--)
{
printf("%c", str[j]);
}
printf("/n");
return 0;
}
#include <stdio.h>
int main()
{
int num, mask;
int p1, p2;
int i = 0;
int j;
char str[50];
printf("Please input a number:/n");
scanf("%d", &num);
printf("Please input p1 p2(<32):/n");
scanf("%d %d", &p1, &p2);
mask = 1 << (p2 - 1);
while(p2 >= p1)
{
if((num & mask ? '1' : '0') == '1')
{
str[i++] = '0';
p2--;
num <<= 1;
}
else
{
str[i++] = '1';
p2--;
num <<= 1;
}
}
printf("the binary system is:");
for(j = i-1; j >= 0; j--)
{
printf("%c", str[j]);
}
printf("/n");
}
#include <stdio.h>
int main()
{
int a, p, v, mask;
int i = 0;
char str[50];
printf("Please input a = ");
scanf("%d", &a);
printf("/n");
printf("Please input p(<32) = ");
scanf("%d", &p);
printf("/n");
printf("PLease input v(0/1) = ");
scanf("%d", &v);
printf("/n");
mask = 1 << 31;
for(i = 0; i < 32; i++)
{
if((a & mask ? '1' : '0') == '1')
{
str[i] = '1';
a <<= 1;
}
else
{
str[i] = '0';
a <<= 1;
}
}
if(v == 0)
{
str[31-p] = '0';
}
else
{
str[31-p] = '1';
}
for(i = 0; i < 32; i++)
{
printf("%c", str[i]);
}
printf("/n");
return 0;
}
#include <stdio.h>
int main()
{
int a, mask;
int i;
int str[50], n_str[50];
printf("Please input a number:");
scanf("%d", &a);
mask = 1 << 31;
for(i = 0; i < 32; i++)
{
if((a & mask ? '1' : '0') == '1')
{
str[i] = 1;
a <<= 1;
}
else
{
str[i] = 0;
a <<= 1;
}
}
for(i = 0; i < 32; i++)
{
if(i == 0)
{
n_str[i] = str[31] ^ str[i+1];
}
else if(i == 31)
{
n_str[i] = str[1] ^ str[i-1];
}
else
{
n_str[i] = str[i-1] ^ str[i+1];
}
}
for(i = 0; i < 32; i++)
{
printf("%d", n_str[i]);
}
printf("/n");
return 0;
}
新闻热点
疑难解答