Easy Questions!Urgent! 
Author Message
 Easy Questions!Urgent!

What do the symbols:   >> and <<  and also ^
do?

--
_____________________________________________________________________

        Civil and Environmental Engineering, University of Michigan
_____________________________________________________________________



Wed, 25 Jun 1997 00:35:11 GMT  
 Easy Questions!Urgent!

: Bitwise Shift Operators: Left Shift and Right Shift

: Operator      <<, >>

: Syntax        shift-expression :
:       additive-expression
:       shift-expression  << additive-expression
:       shift-expression  >> additive-expression

: The shift operators shift their first operand left (<<) or right (>>) by
: the number of positions the second operand specifies.

: Both operands must be integral values. These operators perform the usual
: arithmetic conversions; the type of the result is the type of
: the left operand after conversion.
: For leftward shifts, the vacated right bits are set to 0. For rightward
: shifts, the vacated left bits are filled based on the type of the first
: operand after conversion. If the type is unsigned, they are set to 0.
: Otherwise, they are filled with copies of the sign bit.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think that the shifts are implementation defined for signed
value. K&R2 states (section 2-9):

        "Right shifting a signed quantity will fill with sign bits
('arithmetic shift') on some machines and with 0-bits ('logical
shift') on others."

That would not be a fun error to try and track down after porting!
ugh!

: The result of a shift operation is undefined if the second operand is
: negative, or if the right operand is greater than or equal to the width
: in bits of the promoted left operand.

--
------------------------------------------------------------------------
|Marc R. Whitten       |"Know the enemy and know yourself; in a hundred|

|Univ. North Texas     |                     --Sun Tzu, The Art of War |
|Denton, Texas 76203   |   (Opinions == Mine && !(Opinions==UNT))      |
------------------------------------------------------------------------



Wed, 25 Jun 1997 14:02:13 GMT  
 Easy Questions!Urgent!


Quote:

>What do the symbols:   >> and <<  and also ^
>do?

in C++ (my version)

<< - "insertion" - It passes data into a stream.  You can think of it as
calling the function over and over with the different parameters from
left to right.  i.e. you could think of cout << "Apples " << "Oranges";
as being the same as (or very similar to) printf("Apples ");
printf("Oranges");

Quote:
>> - "Extraction" - The same as above, but instead of passing in a series

of parameters, you accept a series of return values.  i.e. you could
think of cin >> ch1 >> ch2; as being the same as (or very similar to) ch1
= getchar(); ch2 = getchar();

in C/C++ (Techy version)

Bitwise-exclusive-OR Operator

Operator        ^

The bitwise-exclusive-OR (^) operator compares each bit of its first
operand to the corresponding bit of its second operand. If one bit is
0 and the other bit is 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.

Bitwise Shift Operators: Left Shift and Right Shift

Operator        <<, >>

Syntax  shift-expression :
        additive-expression
        shift-expression  << additive-expression
        shift-expression  >> additive-expression

The shift operators shift their first operand left (<<) or right (>>) by
the number of positions the second operand specifies.

Both operands must be integral values. These operators perform the usual
arithmetic conversions; the type of the result is the type of
the left operand after conversion.
For leftward shifts, the vacated right bits are set to 0. For rightward
shifts, the vacated left bits are filled based on the type of the first
operand after conversion. If the type is unsigned, they are set to 0.
Otherwise, they are filled with copies of the sign bit.
The result of a shift operation is undefined if the second operand is
negative, or if the right operand is greater than or equal to the width
in bits of the promoted left operand.

Quote:

>--
>_____________________________________________________________________

>        Civil and Environmental Engineering, University of Michigan
>_____________________________________________________________________



Wed, 25 Jun 1997 04:29:44 GMT  
 Easy Questions!Urgent!
|> What do the symbols:   >> and <<  and also ^ do?

The first is the right shift operator, second is left shift, and the last is
the bitwise exclusive-or.
--





Wed, 25 Jun 1997 08:42:45 GMT  
 Easy Questions!Urgent!

: What do the symbols:   >> and <<  and also ^
: do?

I would like to thank the many people who answered this question for
me so quickly.  

Also, I apologize for taking up space discussing what I was told was
an elemental question and could be found in any C book.

I work part-time in a medium-size computer support group that works
only in fortran on Vaxes.  We were having trouble with a bit of code
(written by others in 'C') being used to support some of our processes.

One of the other programmers (much more brilliant than me - but even
less experienced with "C" - and without immediate net access) asked
me what these symbols meant.  Of course, we have no "C" books in any
of the offices, and the person who designed and sent a copy of the code
to us - promptly took off on vacation.

Sorry for the intrusion - and thanks again for the helpful responses.

: --
: _____________________________________________________________________

:       Civil and Environmental Engineering, University of Michigan
: _____________________________________________________________________

--
_____________________________________________________________________

        Civil and Environmental Engineering, University of Michigan
_____________________________________________________________________



Fri, 27 Jun 1997 01:27:36 GMT  
 Easy Questions!Urgent!

 >: What do the symbols:   >> and <<  and also ^
 >: do?

 >I would like to thank the many people who answered this question for
 >me so quickly.  

 >Also, I apologize for taking up space discussing what I was told was
 >an elemental question and could be found in any C book.

I wish I knew where to find a simple text file that outlined the
basic components and vocabulary of C programming.  It would not
need be verbose, but could be used to give a novice an overview
of the subject.  
--

214/888-0471



Fri, 27 Jun 1997 03:20:33 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. URGENT: A very easy question

2. URGENT ! HELP NEWBIE plz - easy dialog question

3. @> two easy easy questions

4. Urgent Help required - should be easy

5. This is a biztalk question but probably an easy question for you C# guru's

6. EASY EASY BEGINNER ??

7. Easy Reference Question

8. AN EASY QUESTION FOR PRO.

9. easy newbie question

10. Really Easy Random Number Question

11. easy sizeof questions

 

 
Powered by phpBB® Forum Software