You are configuring a microcontroller (uC) to sample a signal connected to an in
ID: 3747178 • Letter: Y
Question
You are configuring a microcontroller (uC) to sample a signal connected to an input pin. Part of the initial setup requires that you clear (turn off) bits #9 and #1 in a 32-bit register, while leaving all other bits unchanged. To work with specific bits, we typically use a second number, called a mask, which has the bit positions we need to alter set to 1, and all other bits are 0. What sequence of binary operators could you use on the register and mask to get the desired result (bits 9 and 1 cleared)?
Explanation / Answer
please do upvote.If you have any problem do comment and i shall be happy to help you.Thanks for using chegg.
-----------------------
Mask : Has the bit positions we want to alter set as 1
Bit positons that should remain unchanged as 0
We shall use Xor operation on register and mask to obtain desired result.
Xor operation is used to alter state of bit.
i.e If it is set(=1) it will clear(=0) it
and viceversa
(assume p shall be bit of register and q bit of mask)
Truth Table of xor
p q r
0 0 0
0 1 1
1 0 1
1 1 0
e.g
first 9 bits in a 32 bit register
register: 100111101
we want to alter 1st and 9th bit
so mask must be one(1) at bit position 1 and 9 will zero(0) otherwise
mask : 1 00000001
no when we perform xor bitwise on register and mask
register: 100111101
xor
mask : 1 00000001
---------------------------
result: 000111100 (obtained using xor table)
the bits at position 1 and 9 are cleared
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.