Ad

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.


Ad
B
Sections
8
Exercises
#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;
}
Ad

© 2024 Garbage Valuegarbage value logo