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
#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;
}

© 2021 Garbage Valuegarbage value logo