업그레이드~!!

비트연산(Bit Operation)

SamSiKi 2010. 9. 30. 22:26

√ 클리어

1. 한비트클리어                        a &= ~(0x1<<5)            : 5 bit

2. 연속된여러비트클리어             a &= ~(0x7<<3)             : 5, 4, 3 bit

3. 떨어진여러비트클리어             a &= ~((0x1<<5)+(0x3<<2))         : 5, 3, 2 bit

 

√ 설정

1. 한비트설정                          a |= (0x1<<5)               : 5 bit

2. 연속된여러비트설정                a |= (0x7<<3)               : 5, 4, 3 bit

3. 떨어진여러비트설정                a |= (0x1<<5)+(0x3<<2)   : 5, 3, 2 bit

 

√ 반전

1. 한비트반전                          a ^= (0x1<<5)              : 5 bit

2. 연속된여러비트반전                a ^= (0x7<<3)              : 5, 4, 3 bit

3. 떨어진여러비트반전                a ^= ((0x1<<5)+(0x3<<2))           : 5, 3, 2 bit

 

√ 비트검사

1. a & (0x1<<5)             : 5 bit           if(a &= ~(0x1<<5))

2. a & 0x10                                       if(a &= 0x10)

 

√ 비트추출

- b=(a>>4) & 0x7                     : 6, 5, 4 bit

반응형