Question: Implement and test the following functionalities through C code fragments. a) Write a C code fragment to check a bit value. Declare three character type
Implement and test the following functionalities through C code fragments.
a) Write a C code fragment to check a bit value. Declare three character type variables ch1, ch2 and mask with initial values of 0x34 and 0x20 for ch1 and mask, respectively. C code should set character type variable ch2 to 1 if the bit 5 in mask is 1, otherwise 0. Note that bits in a byte are numbered from 0 (lsb) to 7 (msb).
b) Write a C code fragment to set a bit value. Declare two character type variables ch1.
c) And mask with initial value of 0x34 for chl. C code should set bit 7 in variable ch1. To 1 using mask without changing any other bit values in ch1. c
d) Write a C code fragment to clear a bit value. Declare two character type variables ch1.and mask with initial value of 0x34 for chl. C code should clear bit 3 in variable ch1. To 0 using mask without changing any other bit values in ch1.
e) Write a C code fragment to toggle a bit value. Declare two character type variables ch1. And mask with initial value of 0x34 for chl. C code should toggle bit 4 in variable ch1. Using mask without changing any other bit values in ch1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
