Chapter - 15: Operations On Bits

Write a program to receive an 8-bit number into a variable and then check if its 3rd and 5th bits are on. If these bits are found to be on then put them off.


B
Sections
8
Exercises

A

B

1

2

3

4

5

6

7

8

9

10

#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<math.h>

#define _BV(x) 1<<x
#define _ls(x,y) x<<y
#define _rs(x,y) x>>y

int main()
{
	unsigned char num, andmask = 0;
	printf("Enter the number : ");
	scanf("%hhd", &num);
	andmask = ~(_BV(3) | _BV(5));
	num &= andmask;
	_getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo