#include <stdio.h>
#include <stdint.h>
uint32_t set_bit(uint32_t data, uint32_t index, uint32_t value)
{
data &= ~(1 << index);
data |= (value & 0x00000001) << index;
return data;
}
char *get_bit_string(uint32_t data)
{
static char string[33] = {0};
char *p = string;
for(uint32_t mask = 0x80000000; mask; mask >>= 1)
{
if(mask & data)
*p++ = '1';
else
*p++ = '0';
}
return string;
}
int main(void)
{
for(uint32_t i = 0; i < 32; ++i)
printf("%s\n", get_bit_string(set_bit(0, i, 1)));
printf("\n");
for(uint32_t i = 0; i < 32; ++i)
printf("%s\n", get_bit_string(set_bit(0xffffffff, i, 0)));
return 0;
}
00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000000100
00000000000000000000000000001000
00000000000000000000000000010000
00000000000000000000000000100000
00000000000000000000000001000000
00000000000000000000000010000000
00000000000000000000000100000000
00000000000000000000001000000000
00000000000000000000010000000000
00000000000000000000100000000000
00000000000000000001000000000000
00000000000000000010000000000000
00000000000000000100000000000000
00000000000000001000000000000000
00000000000000010000000000000000
00000000000000100000000000000000
00000000000001000000000000000000
00000000000010000000000000000000
00000000000100000000000000000000
00000000001000000000000000000000
00000000010000000000000000000000
00000000100000000000000000000000
00000001000000000000000000000000
00000010000000000000000000000000
00000100000000000000000000000000
00001000000000000000000000000000
00010000000000000000000000000000
00100000000000000000000000000000
01000000000000000000000000000000
10000000000000000000000000000000
11111111111111111111111111111110
11111111111111111111111111111101
11111111111111111111111111111011
11111111111111111111111111110111
11111111111111111111111111101111
11111111111111111111111111011111
11111111111111111111111110111111
11111111111111111111111101111111
11111111111111111111111011111111
11111111111111111111110111111111
11111111111111111111101111111111
11111111111111111111011111111111
11111111111111111110111111111111
11111111111111111101111111111111
11111111111111111011111111111111
11111111111111110111111111111111
11111111111111101111111111111111
11111111111111011111111111111111
11111111111110111111111111111111
11111111111101111111111111111111
11111111111011111111111111111111
11111111110111111111111111111111
11111111101111111111111111111111
11111111011111111111111111111111
11111110111111111111111111111111
11111101111111111111111111111111
11111011111111111111111111111111
11110111111111111111111111111111
11101111111111111111111111111111
11011111111111111111111111111111
10111111111111111111111111111111
01111111111111111111111111111111
请按任意键继续. . .
|