Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How do I do x ^= m in DB Pro?

Author
Message
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 28th Jun 2003 18:40
Ok, this is a bit naughty I admit.

I am wondering what on earth the following bit of C code does:

x ^= m

I obviously know what x += m, x -=m, x &= m, etc. etc. do. But I've never seen x ^= m before.

Please can someone explain. I can then port this line into DB Pro.

Awfully gratefully yours

Philip
Drifter
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 28th Jun 2003 18:44
I'm not to sure but I think ^ means to the power of ...
For example 2^3 = 8

Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 28th Jun 2003 21:17
Then again, as far as I know C doesnt use the ^ sign, but uses the function pow() instead, but I could be wrong. If ^ does mean to the power of here, x ^= m means x=x^m.

Whatever I did I didn't do it!
Bloodshot
21
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 28th Jun 2003 22:26 Edited at: 28th Jun 2003 23:33
Yes Drifter, the ^ (circumflex) character is used to raise a number to a given power, (i.e. multiply a number by itself):




Another example program using the power symbol:



Philip, that x^=m formulae you've given does seem to be C's shorthand use of the assignment operator, so:
x^=m is shorthand for:
x=x^m, as Kentaree said.

Otherwise, if the formulae was a condition you took from an If statement, for example:
If x^=m
Then, it could be shorthand for:
If x^0=m
But if that's the case, why not just write: If M=1, because any number used with ^0 will always return 1 ???
However, saying that, if it's shorthand for:
If x^1=m, then you've got a case!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 29th Jun 2003 12:56
Thanks chaps. All your thoughts are very helpful.

The original C code that I am porting is definitely:

x ^= m

Having gone through the purpose of the code, I think its almost certainly a "to the power of" command. I will substitute:

x = x^m in my code instead.

Cheers

Phil

Login to post a reply

Server time is: 2024-09-20 13:42:24
Your offset time is: 2024-09-20 13:42:24