Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Clarification required for Bitwise shift right sig...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Clarificat ion required for Bitwise shift right signed operator
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 05:42 PM
Hi guys
Reading the Apex Developer's Guide p65 (Winter 13) and would like to see if someone can explain something to me regarding the Bitwise shift right signed operator.
This is what it says:
x >> y
Shifts each bit in x to the right by y bits so that the low order bits are lost, and the new left bits are set to 0 for positive values of y and 1 for negative values of y.
So I was trying to figure out what is 50 >> -2
50 in binary is 00110010.
because y is negative, I assume what it means it shifts each bit in 00110010 to the right by 2 bits and the new left bits are set to 1 because y is negative.
I thought that would mean
00110010 ->
10011001 ->
11001100
And that would be something other than 0.
However, when I tried to use Eclipse to do this
system.debug(50 >> -2);
the result is 0.
In fact, no matter what x and y are, as long as y is negative, the result seems to always be zero.
Am I not understanding something properly?
Thanks
King
Re: Clarificat ion required for Bitwise shift right signed operator
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 07:54 PM
The docs are updated to API 27.0. It is likely that <=26.0, negative shifts are automatically zeroed out. I don't have an answer for this immediately, because I do not have a Spring 13 sandbox.
~ sfdcfox ~
I am a sandwich. That is all.

