473,222 Members | 1,738 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,222 software developers and data experts.

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 3914
<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
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.
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
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
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
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...
8
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. ...
4
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...
3
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...
5
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
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...
11
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
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.