本文目录一览:
在线急求C语言上机考答案!自定义函数,实现将一个整数的高16位和低16位互换
int main()
{
int x;
while( scanf( "%d", x ) == 1 )
{
int a = x 16;
int b = x 16;
printf( "%d\n", a , b, a + b );
}
return 0;
}
十进制数如何转16位二进制数,用c语言
#include stdio.h
#include stdlib.h
#include string.h
void DtoOx(int x)
{
char str[] = "0123456789ABCDEF";
char stack[100]="";
int i = 0;
int temp = x;
while (x)
{
stack[i] = str[x % 16];
x = x / 16;
i++;
}
printf("%d 的十六进制是:%s\n", temp, stack);
}
int main()
{
DtoOx(31);
system("pause");
return 0;
}
c语言编程将16位无符号数的高8位和低8位交换.
取出高8位,然后右移8位,再取出低8位,然后左移8位,再把它们相加就可以了,代码:
#includestdio.h
unsigned short MyConvert(unsigned short sval)
{
return ((sval0x00ff)8) + ((sval0xff00)8);
}
int main()
{
unsigned short sval = 0xabcd;
printf("%d,0x%X\n", sval, sval);
sval = MyConvert(sval);
printf("%d,0x%X\n", sval, sval);
return 0;
}
测试截图: