473,804 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a logic shift operator in C++?

Dear all,

Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.

Thanks!

-Andy

Sep 3 '06 #1
9 3951
<yu******@gmail .comwrote:
>Dear all,
>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
No, there is no built-in logical shift right.

Steve
Sep 3 '06 #2
Steve Pope posted:
>>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.

As far as I know, it's implementation-defined as to whether it's logical
shift or arithmetic shift.

No, there is no built-in logical shift right.
You could probably make one yourself by using a combination of things:

(1) Macros to determine whether the system is sign-magnitude, one's
complement or two's complement.
(2) Usage of the IMAX_BITS macro (you can do a Google Groups search for
this.)
(3) Usage of bitwise operators.

It wouldn't be a mammoth task.

--

Frederick Gotham
Sep 3 '06 #3
yu******@gmail. com writes:
Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.

Jens
Sep 3 '06 #4
"Jens Theisen" writes:
>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.

It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.
Actually, there is an established meaning for those two phrases.

Hint: The operation performed does not depend on the value of the operand.
Sep 3 '06 #5
osmium wrote:
"Jens Theisen" writes:
>>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.

Actually, there is an established meaning for those two phrases.
Yes, and they mean exactly the same thing when applied to unsigned integers.

--
Clark S. Cox III
cl*******@gmail .com
Sep 3 '06 #6
"Clark S. Cox III" writes:
osmium wrote:
>"Jens Theisen" writes:
>>>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.

Actually, there is an established meaning for those two phrases.

Yes, and they mean exactly the same thing when applied to unsigned
integers.
The hardware instruction repertoires that I know of that provide both
arithmetic and logical shifts have four shift instructions, not three.
Unless you are terribly clever it is going to take longer to force a
preliminary step of seeing what the value of the operand is, before doing
the shift. YMMV.
Sep 4 '06 #7
osmium wrote:
"Clark S. Cox III" writes:
osmium wrote:
"Jens Theisen" writes:
>
Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.
Actually, there is an established meaning for those two phrases.
Yes, and they mean exactly the same thing when applied to unsigned
integers.

The hardware instruction repertoires that I know of that provide both
arithmetic and logical shifts have four shift instructions, not three.
Unless you are terribly clever it is going to take longer to force a
preliminary step of seeing what the value of the operand is, before doing
the shift. YMMV.
What are you talking about hardware instruction repertoires for? I was
simply pointing out that, for unsigned integers, arithmetic and logical
shifts are 100% identical; There is no sign bit to sign extend; there is
no decision to be made.
--
Clark S. Cox III
cl*******@gmail .com
Sep 4 '06 #8
osmium wrote:
"Jens Theisen" writes:
>>Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.

It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.

Actually, there is an established meaning for those two phrases.

Hint: The operation performed does not depend on the value of the operand.
No, but on the type.

Hint: "singned"/"unsigned" doesn't say anything about the value.
Sep 4 '06 #9
osmium wrote:
"Clark S. Cox III" writes:
>osmium wrote:
>>"Jens Theisen" writes:

Is there a logic shift operator in C++? I tried ">>", it is an
arithmeti c shift operator.
It's arithmetical or logical depending on whether or not the integer
you are shifting is signed or not.

Actually, there is an established meaning for those two phrases.

Yes, and they mean exactly the same thing when applied to unsigned
integers.

The hardware instruction repertoires that I know of that provide both
arithmetic and logical shifts have four shift instructions, not three.
Really? I don't know many, but those that I know only have three, because
there is no difference between a logic and an arithmetic left shift, but
there is one for the right shift. Sometimes, however, there are two
different names on assembler level for the left shift that just resolve to
the same instruction.

Sep 4 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
26544
by: Mehta Shailendrakumar | last post by:
Hello, Can anyone suggest me operator to perform arithmetic shift in C? May it be for a perticular compiler. Thank you in advance. Regards, Shailendra
3
6469
by: Simon Johnson | last post by:
Is there an inbuilt circular shift operator in c#? I've googled it but because c# happens to be musical note.. i get a large noise to signal ratio :P Simon.
4
13061
by: Kevin | last post by:
I was looking through some source code and noticed the used of the C# << operator. Why is this being used here and under what circumstances is an left-shift operator useful. internal enum InterestLevel { Ignore = 0, Display = 1<<0, Interesting = 1<<1, Parents = 1<<2,
8
2434
by: Chua Wen Ching | last post by:
Hi, I had some beginner questions. Do we need Shift << >> or Logical AND OR XOR operator in our daily programming? I am not sure why i need to use it? I had some samples of c# codes using it. Can someone share their experiences why someone should use those operators and what type of scenarios? Any good snippets and example?
4
2225
by: Markus Hahn | last post by:
While coding some binary data handling I found this IMHO strange behavior: Dim bToShift As Byte = 1 bToShift <<= 9 Console.WriteLine("and the value is {0}", bToShift) The output is "2", I expected it to be zero (outshifted bits don't come back). The rule I determined is: whatever the shift operator S is, its real value is (S mod 8). Is this as designed? I read the VB lanuage specification, but I cannot find anything there which would...
3
2631
by: ERE | last post by:
Pardon me if this has been asked a million times -- but I thought that because of generics, the right shift operator was supposed to change with C# 2.0. I thought it was supposed to change from ">>" to "> >", to distiguish it from nested generics. But I've been using VS2005, and when I put in the new syntax I get an error message, whereas the old syntax, as shown in the following code continues to work fine. What am I missing? ...
5
12801
by: LinuxGuy | last post by:
Hi, I want to add bits to present number. Shift operator pushes bits and add '0' at the end. I want to shift bits and want to add 1 at end Ex, 1)
24
3190
by: Nishu | last post by:
Hi All, Could you please explain whether C standard supports logical right shift operation using some operator? I know somewhere I read about >>operator. I thought, it is in C but i think i'm wrong about it. No where google helps me determining this lapse in my memory. MSVC 6 compiler gives me error. Thanks && Regards,
11
1905
by: Bob Altman | last post by:
Hi all, I want to write a generic class that does this: Public Class X (Of T) Public Sub Method(param As T) dim x as T = param >3 End Sub End Class
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.