- 3 25 Lab Write A Program To Determine If A Number Is Odd Or Even Using A Bitwise Operator If You Look At The Binary Rep 1 (43.43 KiB) Viewed 26 times
3.25 LAB: write a program to determine if a number is odd or even using a bitwise operator If you look at the binary rep
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
3.25 LAB: write a program to determine if a number is odd or even using a bitwise operator If you look at the binary rep
3.25 LAB: write a program to determine if a number is odd or even using a bitwise operator If you look at the binary representation of any number the LSB will tell you it is odd or even if the L58 50 it's an even number, if the L58 is 1. is an odd number For example 3 is 0011 and it's ood, Bis 1000 and it's even it you mask out all other bits except for the se, you'll have ether a fora The term 'mank out means to replace all the bits you dont care about with Os, just leaving the bit you are nterested in The mask operation is done with a bitwise AND Which is the operator For example 255 - 11111111 If you maskout bits 7 to 1. youll end up with just 000000011 You can now use that in a conditional expression Complete the following program 073 LA ACTIVITY 3.25.1.LAB write a program to determine if a number is odd or even uninga bwise contor mainc labena - is liveligion 1 include <stdio.h> int main() int ; 4 5 5 7 9 10 11 12 13 14 15 16 17) printf("enter number scanfod",n) if(replace with your code - mask out everything but the 58) printf("it's odd number");//for odd no SS else printft's even number for even return Develop mode Submit mode Run your program as often as you like before submitting for grading Bleon type any needed input values in the first box, then click Run program and observe the programs output in the Second box Enter program Input (optional) if your code recures incut values, provide them here mains Input (from above- Output (shown below) Run program Program output displayed here