-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp-2-1.c
36 lines (30 loc) · 818 Bytes
/
exp-2-1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*************************************************************************
> File Name: exp-2-1.c
> Author: xiaoxiaoh
> Mail: [email protected]
> Created Time: Wed Jun 28 09:50:27 2017
************************************************************************/
/*
* Write a C program to check Least Significant Bit (LSB) of a number is set or not.
*
* Example:
*
* Input number: 11
*
* Output: Least Significant Bit of 11 is set (1).
*
*/
#include <stdio.h>
int main()
{
int num;
/* read a number from user */
printf("Enter a number: ");
scanf("%d", &num);
/* if (num &1) evaluates to 1, the LSB is 1, else LSB is 0 */
if(num & 1)
printf("Least significant bit(LSB) of %d is set(1).\n", num);
else
printf("Least significant bit(LSB) of %d is set(0).\n", num);
return 0;
}