Bit Masking To access or affect only the bits we

Bit Masking To access or affect only the bits we
1 / 1
Bit Masking To access or affect only the bits we - slide 1 of 11 Bit Masking To access or affect only the bits we - slide 2 of 11 Bit Masking To access or affect only the bits we - slide 3 of 11 Bit Masking To access or affect only the bits we - slide 4 of 11 Bit Masking To access or affect only the bits we - slide 5 of 11 Bit Masking To access or affect only the bits we - slide 6 of 11 Bit Masking To access or affect only the bits we - slide 7 of 11 Bit Masking To access or affect only the bits we - slide 8 of 11 Bit Masking To access or affect only the bits we - slide 9 of 11 Bit Masking To access or affect only the bits we - slide 10 of 11 Bit Masking To access or affect only the bits we - slide 11 of 11
Bit Masking To access or affect only the bits we want, we need to construct a byte with bits set in the locations of interest This byte is called a bit mask Use the bit mask with the appropriate bit-wise operator to get the desired

Related Topics

Download this presentation From Below

"Bit Masking To access or affect only the bits we" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

01
Bit Masking To access or affect only the bits we want, we need to construct a byte with bits set in the locations of interest
This byte is called a ‘bit mask’
Use the bit mask with the appropriate bit-wise operator to get the desired result:
To set bits: bit-wise OR ( | ) with the bit mask
To clear bits: bit-wise AND ( & ) with the negated bit mask<br>
02
Bit Masking Example 1 Set bits 3, 5, and 7 in DDRD (make pins to be OUTPUTS) without affecting the other bits (port-style):
recall: DDRD = 0b10101000; but this would make pins 6, 4, 2, 1, and 0 to be INPUTS, which might not be what we want
Instead:
Construct a bit mask with 1s in bit positions 3, 5, and 7 and 0s everywhere else
Bit-wise OR with DDRD and assign back to DDRD<br>
03
Bit-Wise OR and AND Bit-wise OR (X | Y) Bit-wise AND (X & Y)<br>