Bitwise Operation
Lecture PPT
Online Lesson
코딩도장 핵심요약: 비트연산자 사용하기 핵심요약
Bitwise Operation in C
자료형과 메모리 주소를 바이트 단위로 구분하여 사용하였습니다. 비트 연산자는 바이트 단위보다 더 작은 비트 단위로 연산하는 연산자입니다.
Example
Set flag: (플래그 |= 마스크)
a |= (1 << k)
Clear flag (플래그 &= ~마스크)
Example:
Toggle flag (플래그 ^= 마스크)
a ^= 1<<k
Read a bit
(Method 1) bit = a & (1<<k) // Shift ‘bit 1’ left by k starting from LSB
(Method 2) bit = (a >>k) & (1) // Shift target ‘bit right by k
Example:
Read multiple bits
Tip: Use Macro
Exercise
Exercise 1
What will be the output ?
Exercise 2
What will be the output?
Exercise 3
Fill in the blanks.
Exercise 4
Download and Read instruction in the given sourcefile.
Apply bitwise operations (Set HIGH,Toggle, Reset etc) as instructed.
Last updated