Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Program Discussion :: Bitwise Operator

Home > Programs > Bitwise Operator

81 / 15

Write a program to reverse the bits in an integer.

Answer:

#include 
#include 
using namespace std;
/* Iterative function to reverse digits of num*/
int reversDigits(int num)
{
    int rev_num = 0;
    while(num > 0)
    {
        rev_num = rev_num*10 + num%10;
        num = num/10;
    }
    return rev_num;
}
/*Driver program to test reversDigits*/
int main()
{
    int num = 4562;
    cout

Asked In :: Aricent

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: