the meaning of " >> "

This is a discussion on the meaning of " >> " within the C++ Programming forums, part of the General Programming Boards category; Hello . I dont know if it is the board that I can send this question or not , sorry ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    177

    the meaning of " >> "

    Hello .
    I dont know if it is the board that I can send this question or not , sorry if I am wrong .
    I have a source code , but I am not sure that if it is in assembly or some another programming language .

    do u know what is the meaning of " >> " or " << " ?

    I know in ' C ' it is shift but in these codes ....?

    here are some parts of the code :
    {IPchecksum & IPTypeOfService & IPLength & IPTypeOfService are variable name}

    Code:
    .set IPchecksum = IPchecksum + (IPVersionLength<<8) + IPTypeOfService
    .set IPchecksum = IPchecksum + (IPTypeOfService<<8) + IPLength
    Code:
    .MACRO UDPSendByte		;send to UDPport byte (given as parameter1)
    	.if ((@0 >> 0)&1)
              out     UDPPort,RegForUDP1
              out     UDPPort,RegForUDP0
    	.else
              out     UDPPort,RegForUDP0
              out     UDPPort,RegForUDP1
    	.endif
    Code:
    in      temp0, UDPPort                  ;load port state
            cbr     temp0, (1<<TxPlusPin)|(1<<TxMinusPin)          ;clear TX+ and TX-
    	mov	temp1,temp0			;store the default state for recovering
    	out     UDPPort,temp1			;back to port as default state - no voltage between TX pins
    
    	sbr     temp0, (1<<TxMinusPin)          ;set TX- (TX+ was cleared)
            mov     RegForUDP0, temp0               ;and store as log0 state
    and also what is the meaning of '@' , is it like pointers in 'c' ??
    are they assembly codes ?

    thanks

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    In C++, they are insertion (<<) and extraction (>>) operators. insertion operators are commonly used to put things onto a stream, and extaction operators to take them off of the stream. for example:
    Code:
    std::cout<<"Hello World";
    puts "Hello World" onto the standard output stream, and
    Code:
    std::cin>>integer;
    takes something (presumably an int) off the stream.

    as for what langauge that code is, I can't help you there. I don't believe it's C++ judging from the comments though.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    New Zealand
    Posts
    20
    That looks like assembler to me... but it has interesting bits of a higer level langauge in it - .if .else .endif etc. As far as i can tell that is propiorty code going thats meant to be run on a dsp on a level 3 network switch or someting similar.

    But in your case the << and >> will be bit shifters.

    Code:
    .set IPchecksum = IPchecksum + (IPVersionLength<<8) + IPTypeOfService
    .set IPchecksum = IPchecksum + (IPTypeOfService<<8) + IPLength
    This bit mearly turns two 8 bit words into a single 16 bit word, by moving IPVersionLength bits 8 bits up (same as multiplying by 256, but faster).

    Code:
    .MACRO UDPSendByte		;send to UDPport byte (given as parameter1)
    	.if ((@0 >> 0)&1)
              out     UDPPort,RegForUDP1
              out     UDPPort,RegForUDP0
    	.else
              out     UDPPort,RegForUDP0
              out     UDPPort,RegForUDP1
    	.endif
    I'm a bit flumouxed by this bit. I think that the @0 is a pin number on the chip, but why bit shift it by 0 places? it does nothing. But it seems to signfy most/least signficant byte first.

    Code:
    in      temp0, UDPPort                  ;load port state
            cbr     temp0, (1<<TxPlusPin)|(1<<TxMinusPin)          ;clear TX+ and TX-
    	mov	temp1,temp0			;store the default state for recovering
    	out     UDPPort,temp1			;back to port as default state - no voltage between TX pins
    
    	sbr     temp0, (1<<TxMinusPin)          ;set TX- (TX+ was cleared)
            mov     RegForUDP0, temp0               ;and store as log0 state
    Again this isn't how I would do it. Presumably both TxMinusPin and TxPlusPin are #defined somewhere, so why not just use their straight values instead of confusing matters with bit shifting?

    The << and >> also work as bit shifters in C and C++.
    A<<1 == A * 2
    and
    A>>1 == A /2 (rounded down).
    You can also get some weird changing of the sign.

    Try this proggie out, with an input of 65535.
    Code:
    #include <stdio.h>
    #include <iostream>
    
    int main()
    {
      int d, c;
      cout << "Please enter a number between -2,147,000,000 and 2,147,000,000" << endl;
      cin >> c;
      cout << "Heres the number bit shifted up(l col), down(m col) and each bit (LSB first, r col)" << endl;
    
      for(d=c; c|d;c<<=1, d>>=1)
        printf("\n%13d%13d%2d", c, d, d&1);
    
      return 0;
    }

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    177

    the meaning of " >> "

    tnx alot for helping .
    I found some tutorial on internet and used it for the meaning of the operators .
    it is AVR microcontroler assembler .
    u r right : >> and << are shift operators and
    @ is used for parameters of macro .
    now I know the operator operations but dont know the logic behind some sentences
    for example why the programmer has written these ?
    Code:
    .if ((@0 >> 0)&1)
    or in some another part for declaring 'IPLength' he used this (UDPSendByte is type of it ):
    Code:
    UDPSendByte   (IPLength >> 8)
    UDPSendByte   (IPLength >> 0)
    can any one tell me why in 2 lines ? and with 2 shifts ?

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    New Zealand
    Posts
    20
    Quote Originally Posted by arian
    now I know the operator operations but dont know the logic behind some sentences
    for example why the programmer has written these ?
    Code:
    .if ((@0 >> 0)&1)
    or in some another part for declaring 'IPLength' he used this (UDPSendByte is type of it ):
    Code:
    UDPSendByte   (IPLength >> 8)
    UDPSendByte   (IPLength >> 0)
    can any one tell me why in 2 lines ? and with 2 shifts ?
    Why he put extraneous bits in I have no idea. But the last two lines of code first send the IPLenth in two parts - first the high byte and then the low byte (presumably its a 16bit number).

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    177
    you said : " first the high byte and then the low byte " .
    sorry but I dont undrestand , can you plz explain more ?

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Say we have a 16-bit integer like so:
    1010111101101001

    And let's call it i. Then,
    i >> 8 is 0000000010101111
    and
    i >> 0 is 1010111101101001

    What UDPSendByte is probably doing is casting it to a byte, truncating the first 8 bits, which means that those two lines are sending the following bytes respectively,
    10101111
    01101001

    Does that make sense?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    177
    yes tnx

  9. #9
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You're welcome.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is the meaning of following declaration?
    By shwetha_siddu in forum C Programming
    Replies: 1
    Last Post: 04-20-2009, 11:50 PM
  2. what is the meaning of "offset"
    By cromologic in forum C Programming
    Replies: 5
    Last Post: 05-02-2008, 10:09 AM
  3. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 08:53 PM
  4. C++ >> Standard Library >> Header File
    By hrk2006 in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2003, 09:30 PM
  5. would you help me with Linked list, please?
    By unhwan in forum C Programming
    Replies: 1
    Last Post: 06-11-2002, 01:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21