468,457 Members | 1,563 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

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 3691
<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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by Mehta Shailendrakumar | last post: by
3 posts views Thread by Simon Johnson | last post: by
4 posts views Thread by Kevin | last post: by
8 posts views Thread by Chua Wen Ching | last post: by
3 posts views Thread by ERE | last post: by
5 posts views Thread by LinuxGuy | last post: by
24 posts views Thread by Nishu | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.