可以使用位域来定义,同时来转换。例如一个32位int型可以如下定义:
struct test{
union
{
int bits_4
struct
{
int bit1 : 8
int bit2 : 8
int bit3 : 8
int bit4 : 8
}
}
}
将test.bit1和test.bit4对调,test.bit2和test.bit3对调即可。
在C语言中转换大小写字母,可用ctype.h头文件中声明的函数toupper和tolower。
toupper:
int toupper(int c)若c为小写字母,则将其转换为大写字母;否则,不转换,直接返回c。
tolower:
int tolower(int c)若c为大写字母,则将其转换为小写字母;否则,不转换,直接返回c。