Dear all,
Is there a logic shift operator in C++? I tried ">>", it is an
arithmetic shift operator.
Thanks!
-Andy
|
|
0
|
|
|
|
Reply
|
yuyang08 (7)
|
9/3/2006 8:20:20 PM |
|
<yuyang08@gmail.com> wrote:
>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
|
|
0
|
|
|
|
Reply
|
spope33 (691)
|
9/3/2006 8:24:21 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
fgothamNO (1668)
|
9/3/2006 8:34:41 PM
|
|
yuyang08@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
|
|
0
|
|
|
|
Reply
|
jth02 (126)
|
9/3/2006 8:46:12 PM
|
|
"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.
|
|
0
|
|
|
|
Reply
|
r124c4u1022 (2252)
|
9/3/2006 10:14:00 PM
|
|
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
clarkcox3@gmail.com
|
|
0
|
|
|
|
Reply
|
clarkcox3 (505)
|
9/3/2006 11:48:55 PM
|
|
"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.
|
|
0
|
|
|
|
Reply
|
r124c4u1022 (2252)
|
9/4/2006 2:04:03 AM
|
|
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
clarkcox3@gmail.com
|
|
0
|
|
|
|
Reply
|
clarkcox3 (505)
|
9/4/2006 2:48:40 AM
|
|
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.
|
|
0
|
|
|
|
Reply
|
ramagnus (3485)
|
9/4/2006 9:39:21 AM
|
|
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.
|
|
0
|
|
|
|
Reply
|
ramagnus (3485)
|
9/4/2006 9:40:49 AM
|
|
|
9 Replies
34 Views
(page loaded in 0.327 seconds)
Similiar Articles: Bitwise operators - comp.lang.fortran... Fortran 95 have infix bitwise operators like C ... > ieor( a, iand( b, c ) ) > > You may also want ior(), and there are also bit ... Stack Overflow Left and right shift operators ... Bitwise operations on .Net enumerators - comp.soft-sys.matlab ...Or maybe there is a function within .Net that can do this operation for me? ... Matlab logical operators - comp.soft-sys.matlab COMPGROUPS.NET | Search ... Bitwise ... Multipliers, dividers, adders etc.... - comp.lang.verilog ...Bear in mind that synthesis must implement the operators as logic ... It may be that there are synthesis tools that can ... by a constant power of 2 is a simple right shift ... Detect integer/arithmetic overflow? - comp.emacsHow is the limited bit-width of the integers > handled? > On Intel there ... Bit-shift on a signed integer - Stack Overflow... arithmetic bit-shift operators work in C, and ... Signed shift of 32-bit int using 16-bit instructions? - comp.lang ...... left shift is the same thing as logic left shift. ... but didn't bother to re-post about it: There ... Stack Overflow... arithmetic bit-shift operators work in C, and ... Signal is connected to multiple drivers - comp.arch.fpga ...I'm writing some glue logic to shift out data over SPI. My problem code is this ... > > > I'm certain there's an easy prepackaged solution to this problem that ... Bit-Shifting in ASM - comp.lang.asm.x86Hello, I was wondering if there is a command in assembly that can shift the bits ... you'd better use the ROL and ROR operators ... Math logic - comp.lang.asm.x86... 64 bit ... avr implementation of fuzzy logic controller through matlab - comp ...... through the DMA controller ... the heavy lifting is being done by ASIC logic ... If there ... How to get envelope from AM signal without phase shift - comp.dsp ... Both I ... enum and operator++ - comp.lang.c++I removed the wrap logic in switch >statement ... There's no undefined behavior given his definition of ... variant { enum type { int_, char_, char ... Operators in C ... Generating all possible combinations of a 5 digit pattern. - comp ...Four common logical operations are used on bits. ... my head whether Ruby has a complement operator ... There's a corresponding right shift, which moves them the other > >way ... Logical shift - Wikipedia, the free encyclopedia... programming languages C, C++, and Go, however, have only one right shift operator, >>. Most C and ... do follow the zero-result concept of the ideal shifter whilst there are ... Is there a logic shift operator in C++? - C / C++Is there a logic shift operator in C++?. C / C++ Forums on Bytes. 7/11/2012 4:16:44 AM
|