Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ Write a program that reads in a decimal number n. Convert the decimal number into binary format and print out the number in

in c++

Write a program that reads in a decimal number "n". Convert the decimal number into binary format and print out the number in binary format. Then, write the following functions to get, set and clear bit at the position "index" and display the corresponding output given below.

/* Retrieve a bit from a number "n" in binary format at position "index" Input: number n, position index where 0 being the right most(least significant) bit Output: bit at position "index" Example: Input: n=10 (in binary 1010), index=0, output: 0*/

int getBit(int n, int index)

/* Set a bit at position "index". This will set a bit to 1 if its 0 or else it will remain unchanged Input: number "n", position "index" where 0 being the right most(least significant) bit Output: Output the binary number after a bit is set at position "index" Example: Input: n=10 (in binary 1010), index=0, output: 11 (in binary 1011)*/

int setBit(int n, int index)

/* Clear a bit at position "index". This will set a bit to 0 if it is 1 or else it will remain unchanged. Input: number "n", position "index" where 0 being the right most(least significant) bit Output: Output the binary number after a bit is cleared at position "index" Example: Input: n=10 (in binary 1010), index=2, output: 10 (in binary 1010)*/

int clearBit(int n, int index)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago