Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:56:00+00:00 2026-05-17T18:56:00+00:00

Pass a integer 2 to this function and then return a integer which is

  • 0

Pass a integer 2 to this function and then return a integer which is 4

x = 2;
x = rotateInt('L', x, 1); 

(left shift the bits by 1)

Example:
00000010 -> rotate left by 1 -> 00000100

but if I pass this:

x = rotateInt('R', x, 3); 

it will return 64, 01000000

Here is the code, can someone correct the error… thanks

int rotateInt(char direction, unsigned int x, int y)
{
    unsigned int mask = 0;
    int num = 0, result = 0;
    int i;

    for (i = 0; i < y; i++)
    {     
        if (direction == 'R')
        {
            if ((x & 1) == 1)     
                x = (x ^ 129);
            else    
                x = x >> 1;
        }
        else if (direction == 'L')
        {
            if ((x & 128) == 1)  
                x = (x ^ 129);   
            else
                x = x << 1;
        }
    }
result = (result ^ x);
return result;   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:56:00+00:00Added an answer on May 17, 2026 at 6:56 pm

    So, I’ll assume you know what right and left shifts are. And that you know the difference between arithmetic and logical shifts.

    C only has arithmetic shifts. It doesn’t do logical shifts, nor does it do rotates. okay I lied, C does logical shifts on unsigned ints.

    A rotate does, well, exactly that: it’s the same as a logical shift, except when you shift past the end of the number, the digits “wrap around” to the other side. For example

    0010 right-rotated is 0001. If you right-rotate again, you get 1000. See, the 1 wrapped around, or rotated, to the other side of the integer.

    The left rotate is similar: 0100 left rotate 1000 left rotate 0001 left rotate 0010 etc.

    Note that rotates don’t keep the sign bit as an arithmetic right-shift would.

    So, C only has arithmetic shifts. So you have to implement the “rotate” part manually. So, take a left-rotate. You would want to:

    1. Capture the value of the left-most bit. (is it a 0 or 1?)
    2. Do a left-shift
    3. Set the right-most bit – which is the bit we talked about in step 1 (which needs to be rotated around) to the correct value, based on what we captured from step 1.

    You should be able to figure out a similar method for right rotates.

    good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass an integer value to a form in .Net so that
When I pass an immutable type object(String, Integer,.. ) as final to a method
In C can I pass a multidimensional array to a function as a single
Is it possible to pass a reference to a function to another function in
Is it possible to pass a function/callback from javascript to a java applet? For
I am trying to pass a member function within a class to a function
Via alert I have the information string 1:CX.PC.PB.0012.S.S which is from alert(c_itemvalue); Then I
hello please me out regarding this function . Its searching script. when i am
I want to pass a python list of strings to a C function expecting
How do you pass $_POST values to a page using cURL ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.