Question

Given an integer N as input, write a program to check whether Least Significant Bit (LSB)...

Given an integer N as input, write a program to check whether Least Significant Bit (LSB) of a number is set or not. Use bitwise operator to solve the problem. Your code should NOT use conditional statement nor loop strucutre. Input: 5 where: First line represents the integer N. Output: Yes Here binary representation of 5 is 0101 and LSB is 1. Assumption: Value of N can be in the range 0 to 10000?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE REFER BELOW CODE

#include<stdlib.h>
#include<stdio.h>

int main()
{
    int N;
    printf("Input : ");
    scanf("%d", &N); //scanning user input
    //0x1 represnt 0001 in binary and ANDing with N gives 1 only when LSB is 1 otherwise 0
    (N & 0x1)?printf("Output : Yes"):printf("Output : No");
    return 0;
}

PLEASE REFER BELOW OUTPUT

Add a comment
Know the answer?
Add Answer to:
Given an integer N as input, write a program to check whether Least Significant Bit (LSB)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program, that would take a negative number as a input from the console,...

    Write a C program, that would take a negative number as a input from the console, and convert it into 2’s complement binary representation. Recall that, there are two steps to that: ● 1’s complement of the positive bitwise representation, which is similar to bit flipping. ○ Find out the appropriate bitwise operator for that, or do it manually. ● Add 1 with the 1’s complement number. ○ Simply add 1 with the number you get in the previous step....

  • Edit, compile, and run the following programs on the UNIX shell: Write a program that takes...

    Edit, compile, and run the following programs on the UNIX shell: Write a program that takes in six commandline arguments and has four functions (described below) that use bitwise operators. The user should enter six space-separated commandline arguments: four characters (any ASCII character) followed by two integers. Anything else should print an error message telling the user what the correct input is and end the program. Convert the commandline input into "unsigned char" and "unsigned int" datatypes. Be careful with...

  • C programming lab: Description: In this lab you will write a program that will contain two...

    C programming lab: Description: In this lab you will write a program that will contain two functions, setlsbs() and getlsbs(). These functions will use bitwise operators to embed and extract "hidden" bits in a character array. Write a program to test your functions as follows: Obtain a random number seed from the command line of your program using command line arguments. Initialize an array p of 8 unsigned char with random numbers from 0 to 255 Initialize a separate unsigned...

  • Exercise 1: Write a C++ program that asks the user to input an integer n followed...

    Exercise 1: Write a C++ program that asks the user to input an integer n followed by n other characters that will be stored in an array. We suppose here that the user will input only lowercase characters between ‘a’ and ‘z’. We also suppose that the user will input different characters. The program will then sort these characters according to an increasing order of their alphabetical order. In this exercise, feel free to use selection sort, insertion sort, or...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

  • Write in C++. Write a program that takes in an integer in the range 20-98 as...

    Write in C++. Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any value not between 20 and 98 (inclusive), the output is: Input must be...

  • Use as few 3-input NOR gates as possible to design a bubble detector circuit for 8-bit thermomete...

    Use as few 3-input NOR gates as possible to design a bubble detector circuit for 8-bit thermometer code. An n-bit thermometer code represents an integer m, with m 1s followed by (n-m) 0s. 1-bit bubble is an error in coding when a solitary 0 (or 1) is found in between two 1s (or 0s). What is the size of your circuit in terms of the number of NOR gates used? Give a gate level schematic diagram for your circuit. Implement...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • Write a program that takes a positive integer n as input from the user and displays...

    Write a program that takes a positive integer n as input from the user and displays an n by n checkerboard. (Hint: your main method could do user input then call the constructor for your GUI with n as the argument.) For example, when n = 5, there are 25 alternating white and black squares inside a square boarder. The lower right corner of the overall pattern must be white. Make sure that adjacent squares are different colors regardless of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT