变换一个二进制反转位的顺序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <stdlib.h>
unsigned int reve_bits(unsigned int value)
{
unsigned int i;
unsigned int answer;

answer = 0;

for (i = 1; i != 0; i <<= 1)//可以是循环与机器的子长无关,从而避免了可移植性问题
{
answer <<= 1;//左移一位
if (value & 1)//
{
answer |= 1;
}
value >>= 1;
}

将输入的大写字母转换为小写

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int ch;
while ((ch = getchar()) != EOF)
{
putchar(tolower(ch));//使用tolower,在其他字符集上也可以;
}
system("pause");
return 0;
}