473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unsigned right shift operator

184 100+
Hi,
can anyone explain the unsigned right shift operator with example?
And also why there is no unsigned left shift operator? is there any specific reason for that?

-Thanks & regards,
Hamsa
Mar 13 '08 #1
2 2957
JosAH
11,448 Expert 8TB
Hi,
can anyone explain the unsigned right shift operator with example?
And also why there is no unsigned left shift operator? is there any specific reason for that?

-Thanks & regards,
Hamsa
Why don't you just write a little test program and see for yourself? Both the
signed and unsigned right shift operator shift their left operand to the right. The
signed shift moves a copy of the leftmost bit (the 'sign bit') in as the new leftmost
bit; the unsigned right shift puts a zero bit there.

Doing the same for a left shift would be (almost) without meaning as a 'signed
left shift' because the rightmost bit isn't a sign bit.

kind regards,

Jos
Mar 13 '08 #2
BigDaddyLH
1,216 Expert 1GB
Why don't you just write a little test program and see for yourself? Both the
signed and unsigned right shift operator shift their left operand to the right. The
signed shift moves a copy of the leftmost bit (the 'sign bit') in as the new leftmost
bit; the unsigned right shift puts a zero bit there.

Doing the same for a left shift would be (almost) without meaning as a 'signed
left shift' because the rightmost bit isn't a sign bit.

kind regards,

Jos
This is a good idea. And to see the binary representation of an int, you can use Integer's toBinaryString method.
Mar 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bill | last post by:
I am trying to convert a Java APP to C# and it appears C# does not have a >>> operator. Does anyone the best way to conver this operator in to c#? Thanks. -- Bill
17
by: Peter Bromley | last post by:
The following code snippet does not seem to work correcly unsigned __int64 result = 0xFFFFFFFFFFFFFFFF; result = result << 64; Debugger.WriteLine(System::String::Format(S"{0:X16}",...
7
by: Marty McFly | last post by:
Hello VB Gurus, I have an unusual requirement to shift an unsigned int right one bit: Dim myVar As UInt32 = UInt32.Parse("123456") Dim myResult As UInt32 myResult = myVar >> 1 However, the...
5
by: Schüle Daniel | last post by:
Hello Newsgroup, I was thinking about integer literals and what default types they get and how they behave when applied to shift operator assume sizeof(int) == sizeof(unsigend int) = 4 ...
6
by: NM | last post by:
I am given an int and have to tell whether the bit representation of that int is a palindrome or not. Here is what I have come up with bool isIntPalindrome(int num) { unsigned int temp = num;...
4
by: techie | last post by:
I have defined a number of unsigned integer types as follows: typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; typedfe long long uint64; Is it...
10
by: krunalb | last post by:
Hi, I am trying to shift unsigned long long value by 64 bits and this is what i get #include <stdio.h> int main() { unsigned short shiftby= 64;
6
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but...
13
by: Martin Wells | last post by:
I commonly use the likes of -1 for max unsigned values, or something like -7 to get 6 away from the max value; sort of like: unsigned x = ... if (-7 == x) puts("x is 6 away from its maximum");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.