I am trying write program in C language on computer for the following steps:
My code
Output test for set / Reset
Set/Reset LSB Enter 1 /0 : 1
128
Set/Reset LSB Enter 1 /0 : 0
0
I belive code is doing what I wanted to do it
I want to check MSB bit after shifting the position. If the MSB bit is set to high then true statement should be print else false statement should be print
How to test MSB bit in the byte ?
- Declare a variable that holds one byte of data and assign it to 0 .
- Data byte = 00000000 ( MSB - LSB)
- Give option to the user so that he can set or reset last bit in the byte.
- For example, suppose the user sets the last bit
- Data byte = 00000001
- Shift LSB to MSB position
- Data byte = 10000000
My code
C:
#include<stdio.h>
#include<stdint.h>
int main ()
{
uint8_t Data_Byte = 0;
uint8_t LSB_BIT;
printf("Set/Reset LSB Enter 1 /0 : ");
scanf("%d", &LSB_BIT );
Data_Byte = ( Data_Byte | LSB_BIT );
Data_Byte = Data_Byte << 7;
printf("%d ", Data_Byte );
return 0;
}
Set/Reset LSB Enter 1 /0 : 1
128
Set/Reset LSB Enter 1 /0 : 0
0
I belive code is doing what I wanted to do it
I want to check MSB bit after shifting the position. If the MSB bit is set to high then true statement should be print else false statement should be print
How to test MSB bit in the byte ?
