楼主测试下这段代码
#ifndef _BIT_
#define _BIT_
#define BIT(n) (1<<(n))
#define bit(n) BIT(n)
#define bit1(n) BIT(n)
#define BIT1(n) BIT(n)
#define BIT0(n) (~(BIT(n)))
#define bit0(n) BIT0(n)
#define enBit(val,n) ((val)|=(bit1(n)))
#define clBit(val,n) ((val)&=(bit0(n)))
#endif
==================
vc6.0测试
#include<stdio.h>
#include<stdlib.h>
#ifndef _BIT_
#define _BIT_
#define BIT(n) (1<<(n))
#define bit(n) BIT(n)
#define bit1(n) BIT(n)
#define BIT1(n) BIT(n)
#define BIT0(n) (~(BIT(n)))
#define bit0(n) BIT0(n)
#define enBit(val,n) ((val)|=(bit1(n)))
#define clBit(val,n) ((val)&=(bit0(n)))
#endif
void main()
{
unsigned int i=0xfffff;
unsigned int a=i;
char cha[32];
a &= bit0(3)&bit0(0);
itoa(a,cha,2);
printf("%032s\n",cha);
enBit(a,30);
itoa(a,cha,2);
printf("%032s\n",cha);
clBit(a,13);
itoa(a,cha,2);
printf("%032s\n",cha);
a |= bit(25) | bit(23);
itoa(a,cha,2);
printf("%032s\n",cha);
}
00000000000011111111111111110110
01000000000011111111111111110110
01000000000011111101111111110110
01000010100011111101111111110110
Press any key to continue
32位以内应该没问题, 更大的没测试 ,,
|