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

  • SEARCH
  • Home
  • 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 6565223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:04:02+00:00 2026-05-25T14:04:02+00:00

Is the right-shift operator in Objective C on OSX/iOS an arithmetic or logical right

  • 0

Is the right-shift operator in Objective C on OSX/iOS an arithmetic or logical right shift?

I can’t find any references that specify whether the right-shift is arithmetic or logical, or if it varies depending on the data type (signed/unsigned) and/or architecture (x86/PPC/x64/ARM).

“Programming in Objective-C 2.0” states that this is effectively undefined, but that conflicts with information I’ve seen elsewhere that compilers attempt to “do the right thing” based on signed-ness of types.

  • 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-25T14:04:02+00:00Added an answer on May 25, 2026 at 2:04 pm

    I did a quick experiment in the iOS simulator, with the following fragment:

    int i = -600;
    
    for (int j = 0; j < 68; j++)
    {
        NSLog(@"j: %d i: %d", j, i);
        i = i >> 1;
    }
    

    Which yielded the result:

    j: 0 i: -600

    j: 1 i: -300

    j: 2 i: -150

    j: 3 i: -75

    j: 4 i: -38

    j: 5 i: -19

    j: 6 i: -10

    j: 7 i: -5

    j: 8 i: -3

    j: 9 i: -2

    j: 10 i: -1

    j: 11 i: -1

    …

    This would seem to indicate that the shift is arithmetic, not logical, because the sign of the answer is preserved.

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

Sidebar

Related Questions

I know that I can perform divide by 2 using right shift. For simplicity,
what is the difference between logical right shift and arithmetic right shift?
I heard that you could right-shift a number by .5 instead of using Math.floor().
I'm trying to find a way to perform an indirect shift-left/right operation without actually
I recently faced a strange behavior using the right-shift operator. The following program: #include
According to here , arithmetic-shift will bit-shift left and right. The right shift preserves
How does one go about doing a logical right shift of negative numbers in
Possible Duplicate: Weird behavior of right shift operator Hello Why both numbers from this
I was looking at F# doc on bitwise ops: Bitwise right-shift operator . The
I would like to know if performing a logical right shift is faster when

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.