LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-01-2004, 11:29 AM   #1
GodSendDeath
Member
 
Registered: Mar 2004
Posts: 71

Rep: Reputation: 15
Operators *^ and >>


Hey everyone;

I've seen in several C programs the use of *^ and >> to manipulate numbers. I've seen *^ in XOR applications and >> in computing checksums in packet headers. What does *^ and >> or << do? Any help would be appreciated


-GSD
 
Old 11-01-2004, 11:53 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Not sure what *^ is but ^ is the XOR operator. you'd do something like some_int ^ some_other_int.

XOR works like AND and OR but only returns true if both bits are different, so you get like:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

Here's an example:
1011
1001
------
0010

>> and << are bit shift operators. >> will shift all the bits in the integer to the right a specified number of times and << will shift the bits left a specified number of times. For instance if you had:

0x59 (01011001 in binary)

you could do 0x59 << 1 to shift all the bits to the left resulting in 10110010 (0xB2 in hex).

Last edited by itsme86; 11-01-2004 at 11:59 AM.
 
Old 11-01-2004, 01:48 PM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I don't think *^ is a valid operator in C++; perhaps there is some way it can be read as a combination of two operators? I can't think of any situations where * would not have a right-hand operand, though. I'd be interested to see the context you saw it in. ^= is the operator for assigning a value using XOR.

As itsme says, though >> is a bitshift operator; it is also overloaded with other meanings, such as when they're used for stream extraction and stream insertion:

Code:
cout << "Enter x: ";
cin >> x;
In C++, you can overload any operator to do anything you want; I'm sure there are other meanings for most operators. But AFAIK you can't create new ones.

Last edited by wapcaplet; 11-01-2004 at 01:50 PM.
 
Old 11-01-2004, 09:10 PM   #4
GodSendDeath
Member
 
Registered: Mar 2004
Posts: 71

Original Poster
Rep: Reputation: 15
Hey, thanks for all the replies. I wrote the symbol "^*" wrong, I mean "^=" and "*=". I had a feeling ^= was XOR operations. Thanks for the replies guys and thanks for clearing things up for me.

-GSD
 
Old 11-01-2004, 09:47 PM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
^= and *= or shortcut asignment operators.

If you had a = a * b you could write it as a *= b.
If you had num1 = num1 ^ num2 you could write it as num1 ^= num2.

It works with any binary operator. It's when you're doing <operand1> = <operand1> <operator> <operand2>.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
about bitwise operators? eshwar_ind Programming 17 10-25-2004 02:13 AM
C++, comparison operators, segfault exodist Programming 1 04-24-2004 03:03 PM
Bitwise operators kamransoomro84 Programming 8 04-22-2004 10:46 PM
operators linuxanswer Programming 3 12-14-2003 06:09 PM
arithmetic operators in Kylix3 (C++) herbie_52 Programming 2 05-23-2003 07:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration