[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Bitwise Operator

Home > Programs > Bitwise Operator

82 / 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: