Chapter - 15: Operations On Bits

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


B
Sections
9
Exercises

A

B

1

2

3

4

5

6

7

8

9

10

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

#define _BV(x) 1<<x

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