|
No. It has to do with the bits of the number, not the actual number.
|
|
|
|
≡
|
2012 Feb 15 at 03:32 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Not in vb.net...
So, I guess we all should be clear about which language we're referring to from here on out... especially if we're going to be posting about all kinds of different languages in a single thread xD
|
|
|
|
≡
|
2012 Feb 15 at 03:44 UTC
|
|
|
|
Hello red team jungler, you came up into my lane.
I have got no mana jus' some enerGG.
Wha-wha-whaa
What did you see how I'm on a killing spree?
Sorry you cannot stop me.
I'll show no mercy.
|
|
|
|
≡
|
2012 Feb 15 at 03:51 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
Rockbomb is right, a^=b is equivalent to a = a^b. As Sprinkles edited in, that is a bitwise XOR. So if we have binary numbers a = 0101 and b = 1100, a ^ b = 1001. Do you see what's going on? Basically it does an XOR (exclusive or) operation against the individual bits of the number. XOR returns true if the two operands are different ( 0 XOR 0 = 0, 1 XOR 0 = 1, etc.)
So given that can you tell me what this does?
code void f(int a, int b) { a ^= b ^= a ^= b; }
|
|
|
|
≡
|
2012 Feb 15 at 16:42 UTC
|
|
|
|
Down Rodeo said: So given that can you tell me what this does?
code void f(int a, int b) { a ^= b ^= a ^= b; }
It switches the variables. a now = b, and b now = a.
|
|
|
|
≡
|
2012 Feb 17 at 02:28 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
I went to go test it, and vb won't let me do it :/
I have no idea what it would do, but I don't think Sprinkles is right.
|
|
|
|
≡
|
2012 Feb 17 at 03:01 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
Who said anything about needing a computer to test? You can write it out by hand. Technically it's not legal C that I showed you; it is better to do
code a ^= b; b ^= a; a ^= b;
but in the end Sprinkles is correct and it flips the variables. I hope you didn't Google it...
As a next question, I dunno. Any requests for a particular area? I know Superjer knows lots.
|
|
|
|
≡
|
2012 Feb 17 at 15:39 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Down Rodeo said: Who said anything about needing a computer to test? You can write it out by hand. Technically it's not legal C that I showed you; it is better to do
code a ^= b; b ^= a; a ^= b;
but in the end Sprinkles is correct and it flips the variables. I hope you didn't Google it...
As a next question, I dunno. Any requests for a particular area? I know Superjer knows lots.
Hmmm, interesting...
So let's say that a is equal to 2, and b is equal to 5.
a ^= b would set the value of a to 32
b ^= a would set the value of b to 25
a ^= b would set the value of a to some ridiculously long number
I guess I'm not understanding how this would work :/
b would start out with a value of 5, and end up with a value of 25. Then a would start with a value of 2, and end up with a number that probably can't even be stored in a double.
Edit: As far as which kind of questions/problems... idk. Just keep giving more stuff like this, I'm learning from it :D
But before the next question, I'd like to understand this one.
|
|
|
|
≡
|
2012 Feb 17 at 20:26 UTC
— Ed. 2012 Feb 17 at 20:28 UTC
|
|
|
|
code a ^= b; b ^= a; a ^= b;
a = 00000010 (binary form of 2)
b = 00000101 (binary form of 5)
a ^= b
a = 00000010
b = 00000111
b ^= a
a = 00000101
b = 00000111
a ^= b
a = 00000101
b = 00000010
If that doesn't make sense then look up bitwise operations.
|
|
|
|
≡
|
2012 Feb 17 at 21:14 UTC
— Ed. 2012 Feb 17 at 21:16 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
sprinkles said: code a ^= b; b ^= a; a ^= b;
a = 00000010 (binary form of 2)
b = 00000101 (binary form of 5)
a ^= b
a = 00000010
b = 00000111
b ^= a
a = 00000101
b = 00000111
a ^= b
a = 00000101
b = 00000010
If that doesn't make sense then look up bitwise operations.
Alright, well that makes a LITTLE more sense, but still doesn't seem right.
How did you get b = 00000111? Cuz 00000111 would equal 7, if you're counting it in binary.
|
|
|
|
≡
|
2012 Feb 17 at 21:18 UTC
|
|
|
|
Rockbomb said: How did you get b = 00000111?
00000010
00000101
00000111
Its an XOR so all the ones are kept, zeros remain zero, and duplicate ones become zero.
|
|
|
|
≡
|
2012 Feb 17 at 21:33 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Ah, so... when you use the "^" operator on a string, it doesn't try to exponentiate the operands (would they still be called operands if they're strings, and not numbers?).
I guess I shoulda actually read up on this XOR stuff... prolly would helped me understand a lot easier xD
Edit: Off topic... Chrome's spell check is telling me that exponentiate isn't a word. It is though, isn't it?
|
|
|
|
≡
|
2012 Feb 17 at 22:20 UTC
— Ed. 2012 Feb 17 at 22:21 UTC
|
|
|
|
I drink to forget but I always remember.
|
|
|
|
≡
|
2012 Feb 17 at 23:02 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Your image is broken, cloud. Probably cuz you seem to link images from sites like 4chan and funnyjunk, which don't allow you to hotlink to their images.
|
|
|
|
≡
|
2012 Feb 17 at 23:44 UTC
|
|
|
|
http://gifbin.com can go suck a fat donkey dick.
I drink to forget but I always remember.
|
|
|
|
≡
|
2012 Feb 17 at 23:54 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
Yeah, you're missing the point of the operator. It's not the exponent, but the XOR as I said. Generally exponents are either ** or just a function call (Math.pow()) for example). Pretty crazy how it works though!
If you any further questions about it, please ask. I'd also like you to research floating point. How are floats *actually stored*?
|
|
|
|
≡
|
2012 Feb 18 at 03:27 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Down Rodeo said: Yeah, you're missing the point of the operator. It's not the exponent, but the XOR as I said. Generally exponents are either ** or just a function call (Math.pow()) for example). Pretty crazy how it works though!
If you any further questions about it, please ask. I'd also like you to research floating point. How are floats *actually stored*?
Well in vb.net, the "^" operator is used for exponentiation, so that prolly played a pretty big part in my confusion. I finally went ahead and read through the wiki page for the XOR operator, and I feel like I understand it now.
Floating points I think I already know. Iirc, it stores a series of integers, and then it also stores how many digits the decimal should be placed at.
So, for the number 2648.14932, it would store the number 264814932, and then it would also store that the decimal should be placed 5 places from the right (or 4 places from the left, maybe?).
I could be wrong, but that's how I recall them working... and I'm too lazy to look it up and see if I'm right xD
|
|
|
|
≡
|
2012 Feb 18 at 03:47 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
That would be something like fixed point, though a better way to do it is to store for example 2 bytes of integer part and 2 bytes of fractional part. Or four of each, go crazy. You can actually implement this yourself if you feel up to it! Yeah, VB is stupid. I admit that initially using the thing that had meant exponentiation to be something different wasn't the best plan, but we're stuck with it now.
So floating point! Get to it!
|
|
|
|
≡
|
2012 Feb 18 at 03:59 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
I haven't researched floating point and how it works, but I don't want this truck to die, so imma make this post and let you know that I would like some more trivia
|
|
|
|
≡
|
2012 Mar 1 at 01:09 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
Look for stuff about floats on altdevblogaday. It's great.
code int x = 5; x = x++ + ++x;
This isn't valid C, why? What is the new value of x?
|
|
|
|
≡
|
2012 Mar 1 at 13:22 UTC
|
|
|
|
Down Rodeo said: Look for stuff about floats on altdevblogaday. It's great.
code int x = 5; x = x++ + ++x;
This isn't valid C, why? What is the new value of x?
I believe even just x = x++ isn't valid, no?
...and that's the bottom line because Mate de Vita said so.
|
|
|
|
≡
|
2012 Mar 1 at 13:43 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
I'm gonna take a stab and say it's cuz C doesn't recognize whitespace, so it would read "x=x+++++x", and I'm gonna take a guess and say the value would come up as 11?
|
|
|
|
≡
|
2012 Mar 1 at 16:43 UTC
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse
2007 Oct 19 • 5486
57,583 ₧
|
Ummm, I think x = x++ is valid, I'd need to check the spec but I don't see why it shouldn't be unambiguous. C recognises the whitespace. As to what x is... Technically it can return anything. It could just crash and that is completely allowed. However, using gcc, I think you would get 13. The reason why is quite subtle and is essentially because no code will be produced for that fragment (it will just end up as a numeric literal, gcc will do the maths for you).
|
|
|
|
≡
|
2012 Mar 1 at 17:06 UTC
|
|
|
Rockbomb
Dog fucker (but in a good way now)
2009 Nov 14 • 2045
|
Wait, C recognizes whitespace?
What about C++, does IT recognize whitespace? It's been a while since I've done anything with it, but iirc it doesn't. Or maybe it recognized spaces, but not linebreaks?
Also, just out of curiosity, why do you use C rather than C++? Don't like OOP?
|
|
|
|
≡
|
2012 Mar 1 at 17:22 UTC
|
|
|
SRAW
Rocket Man
2007 Nov 6 • 2525
601 ₧
|
There IS no reason to use c++ over c, but c is simpler soo
|
|
|
|
≡
|
2012 Mar 1 at 22:37 UTC
|
|
|
|