Question

CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main () function: 1. Declare an int variable, name it number. 2. Prompt the user to enter a whole number- read it into the variable. Validate the range in a loop. Valid range is 20 to 200 both inclusive . 3. Display the number to the screen (base 10) 4, Display the number in hexadecimal (Use %X) 5. Display number to the screen -It will be a negative number. 6. Determine the rightmost bit in the number, display it to the screen (O or l): int maskRight-11 0000 0001 Do a bitwise & between the mamber and the maskRight If it is equal to 0, the rightmost bit is 0, otherwise, it is 1 7. Determine the third bit from the right in the number int mask3rd- 10? // 0000 0100 Do a bitwise & between the number and mask3rd-if it is equal to 0 the 3rd bit in the number is 0, otherwise it is 1. Shift the number to the left by 2 bits - display the updated number to the screen (It will be multiplied by 2 twice). 8. 9. Shifthe updated number to the right 3 bits -display the outcome to the screen. 10. Add the rerun loop to the program - allowing the user rerun the program with different input numbers. (Hint: do-while loop)
media%2F676%2F67630625-788c-446e-8138-11
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#include<stdlib.h>

int main()

{

int mask = 1,number,choice;

do

{

while(1)

{

printf("Enter a whole number between 20 and 200. inclusive : ");

scanf("%d",&number);

/*Check the input is with in the range of 20 and 200 */

if(number >= 20 && number <= 200)

{

break;

}

printf("\n");

}

printf("The input number is : %d\n\n",number);

/*Printing Hexadecimal value of a number*/

printf("The input number in Hexadecimal : %X\n\n",number);

/*Printing the negation value of a number */

printf("The ~number is : %d\n\n",~number);

/*Check whether the number lsb is zero or not Eg: (1000 0000) & (0000 0001)*/

(number & mask) ? printf("The right most bit is 1\n\n") : printf("The right most bit is 0\n\n");

/*Shift the mask to left 2 times to find the 3rd bit value */

mask = mask << 2;

/*Check whether the third bit is zero or not Eg: (1000 0000) & (0000 0100)*/

(number & mask) ? printf("The right most bit is 1\n\n") : printf("The right most bit is 0\n\n");

/*Shift the number two times left */

number = number << 2;

printf("Number after 2 bits shift to the left = %d\n\n",number);

/*Shift the number three times right */

number = number >> 3;

printf("Number after 3 bits shift to the right = %d\n\n",number);

printf("Do you want to continue this program and test a new number\n");

printf("Enter 1 for 'YES' and 0 for 'NO'. ");

scanf("%d",&choice);

printf("\n\n");

}while(choice);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main...
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
  • PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut...

    PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut the The program will ask the user to enter an unsigned also how many bits for the shift operation. Display the entered operation in both decimal and binary formats, vise shirt operators to shift the bits to the right >> or the left << user to enter an unsigned integer number, choose right shift or left shift, and orauon. Display the entered number and...

  • This daily will allow you to practice more with the bit wise operators and shifts. Consider...

    This daily will allow you to practice more with the bit wise operators and shifts. Consider the following modification of the main program from daily 3: #include void set_flag(unsigned int* flag_holder, int flag_position); void unset_flag(unsigned int * flag_holder, int flag_position); int check_flag(unsigned int flag_holder, int flag_position); void display_32_flags(unsigned int flag_holder); int main(int argc, char* argv[]) { unsigned int flag_holder = 0; set_flag(&flag_holder, 3); set_flag(&flag_holder, 16); set_flag(&flag_holder, 31); display_32_flags(flag_holder); unset_flag(&flag_holder, 31); unset_flag(&flag_holder, 3); set_flag(&flag_holder, 9); display_32_flags(flag_holder); return 0; } Write the...

  • In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned...

    In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned int * flag-holder, int flag-position); int check-flag (unsigned int flag-holder , int flag-position); void display -32_flags (unsigned int flag-holder); int main(int argc, char* argv (1) unsigned int flag -holder = 0; set-flag (& flag-holder, 3); set-flag (& flag-holder, 16); set-flag (& flag-holder, 31); display-32-flags (flag-holder); unset-flag(& flag-holder , 31); unset-flag (& flag-holder, 3); set-flag (& flag-holder , 9); display-32-flags (flag-holder ); return 0; Write...

  • Write a program that will ask the user for a decimal number such as 18 and...

    Write a program that will ask the user for a decimal number such as 18 and prints the 16 bit binary equivalent of the number: 0000 0000 0001 0010 NOTE: Your output should be a binary string formatted by nibbles (spaces every four bits): 0000 0000 0010 1110 1010 0111 1. Ask the user for a number and store it in an int variable called “number”. 2. Find out how many bits you want to use to represent this number....

  • 26. The is a group of bits that tells the computer to perform a specific operation...

    26. The is a group of bits that tells the computer to perform a specific operation A). program counter B). Opcode C). register D). microoperation 27. A condition called occurs in unsigned binary representation of a number when the result of an arithmetic operation is outside the range of allowable precision for the given number of bits. A). underflow B). 2's complement C). overflow D) bitwise complement 28. An iteration of the fetch-decode-execute cycle includes which of the following events?...

  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • Objective: In this lab, we will learn how we can design sequential circuits using behavioral mode...

    Just need the code for the random counter,Thanks Objective: In this lab, we will learn how we can design sequential circuits using behavioral modelling, and implementing the design in FPGA. Problem: Design a random counter with the following counting sequence: Counting Sequence: 04 2 9 168573 Design Description: The counter has one clock (Clock), one reset (Reset), and one move left or right control signal (L/R) as input. The counter also has one 4bit output O and one 2bit output...

  • Lab 7 Add three instance variables to your class RightTriangle from lab 5. The first two...

    Lab 7 Add three instance variables to your class RightTriangle from lab 5. The first two are of type int and are called xLoc and yLoc and the third is of type int called ID. Also add a static variable of type double called scaleFactor. This should be initialized to a default value of 1. Update the constructor to set the three new instance variables and add appropriate get and set methods for the four new variables. All set methods...

  • COMP1410 - Lab Exercises #3 (Due at the end of the lab period or beginning of...

    COMP1410 - Lab Exercises #3 (Due at the end of the lab period or beginning of the next) Start Date: Oct. 1st, 2019 Objectives: Practice dealing with 2D arrays. Create a two dimensional array (e.g. int A2D[M] [N] ;) of size MXN to store integer values. Use #define M 4 and N 3 to start. (Using symbolic constants instead of hard coding the array sizes improves scalability). Create an interactive menu within main() for this program (call it Lab3.c) with...

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
ADVERTISEMENT