Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Minor COG discoveries
Minor COG discoveries
2003-11-15, 8:42 AM #1
I was fooling around this morning and found out some interesting things.

1. The ^ operator, exclusive OR (XOR). Compares two values, and returns a value that has its bits set if one or the other value has its corresponding bits set, but not both.
Code:
1 ^ 1 == 0
1 ^ 0 == 1
0 ^ 1 == 1
0 ^ 0 == 0


Can be used as bitwise or logical, e.g. if(var1 ^ var2).

It can be useful for swapping two variables, other than a string, in COG.
Code:
X = X ^ Y;
Y = Y ^ X;
X = X ^ Y;



2. The ! operator, logical NOT. This may not be new, but I can't remember seeing it in any LEC or custom COGs, but I haven't looked in a while. if(!(var1 == var2)) is the same as if(var1 != var2). It's not really useful in COG since there aren't any boolean data types (I tried bool and boolean with values of true/false and 0/1 to no avail), and I'm pretty sure COG doesn't think of 0 as false and 1 as true, so if(var1) won't work, neither will if(!(var1).

3. Crude return functions with the user messages. In real languages, you can make a function that will accept parameters, and return a new value, so you can go var1 = pow(5, 6); and var1 will become 5 to the 6th power, which was figured out in the pow function.

Code:
symbols
...
message      user0      // Power "return function", pass two numbers with SendMessageEx and receive the first parameter to the second.
...
      printInt(SendMessageEx(GetSelfCog(), user0, X, Y, 0, 0));
...

user0:      // Power "return function".
      temp = GetParam(0);
      for(I = 0; I < GetParam(1) - 1; I = I + 1)
            temp = temp * GetParam(0);
      ReturnEx(temp);



None of this is really useful, but I thought someone might find it interesting.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-11-15, 9:11 AM #2
Hmm if we can use pow(A, B); then we can make many intresting things..

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-11-15, 9:19 AM #3
XOR is definitely a nice discovery, but the other two should be well known.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-11-15, 9:24 AM #4
I also tried the ~ operator, which is inversion or Ones Complement, and it doesn't work. I also messed around with C-style arrays, which only crashed JK. I also tried concatenation with string variables, but that doesn't want to work, either. And I tried accessing individual string characters like you might in C/C++ (for C-style or STL strings), with the [] subscript operator, e.g. print(myString[5]); didn't print out the fourth character in the string.

Oh, heh, I also tried pointers, which I was certain couldn't be there, but I tried anyway, didn't work, heh.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.

[This message has been edited by Emon (edited November 15, 2003).]

[This message has been edited by Emon (edited November 15, 2003).]
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-11-15, 12:23 PM #5
The first one is . . . interesting . . . the others are old news.

------------------
Fight the future.
And when the moment is right, I'm gonna fly a kite.
2003-11-15, 7:14 PM #6
Alright; I haven't done this in years, I wasn't sure.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-11-16, 3:57 AM #7
hm i got question: How to print string and int in one line?
Like Print("number is.."[int]); or? Possible?

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-11-16, 7:23 AM #8
jkStringConcatFormattedInt();

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-11-17, 1:07 PM #9
ok...... for the people among us that dont speek the english good what exactly dose ^ do again??


p.s. it must have been fun in the old days finding new operatiors, and fantastic discoverys in cog verbs.. DANG why wasent i born five years earlyer?

------------------
I am pjb.
Another post......
another moment of my life wasted.....
at least i made a level.
PJB's JK page's

-the PJB jedi rule book-
rule one, "never trust a bartender with bad grammar"-kyle katarn in JO

Rule Two, "Gravity is a crule misstress" -kyle katarn in MotS, and the alternatior MK I in AJTD

rule three, "asprines good, but it hasent got the kick of morphine. and its not gonna stop the hurting in my arm, the ones thats on the otherside of the room i mean" -the alternatior
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2003-11-17, 3:05 PM #10
Lookup bitwise operators on Google, you should find something on XOR.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.

↑ Up to the top!