| |
| |
| |
|
Page: 1 2 3 4 5 6 7
Comments:
<0> nope it should be something else <1> melfar did tell you what it was. <0> yeah, but what's bitwise ? :) <1> It means it operates on the bits. <2> and it's wise <0> wait, if I do a>>1, what would the result be ? <3> NrGSTaR, it helps if you think of variable values in terms of their binary representations. <1> 6 = 0x06 = 00000110. <1> 6 >> 1 = 0x06 >> 1 = 00000011 <0> oh. <1> It shifts the bits to the right. <0> so a>>1 will be 0x0a basically <1> No. <1> a>>1 will be whatever value is in a, shifted one bit to the right. <0> binary. <0> and the result (cout << a;) will be binary or back to normal ?
<3> It'd be the regular representation <1> Errrr... <0> I guessed so <0> got it :) <3> Using bitwise operators doesn't change the way it's represented using print functions and such <0> very simple :) althoug why would i want to use it ? <1> I think you'Re confusing things. <3> It comes in handy for things such as hardware interactions, cryptography, etc. <1> cout is a stream. It overrides the bitwise operators. It does not do bitshifting. <0> oh. <0> yeah. <0> yes, i meant in a function <3> Oh good eye DrkMatter <1> What I was telling you about are the effects of << >> with integer values. <1> int a=4; cout << a; a = a >> 1; cout << a; <0> like.. a=6, b=a<<1; cout <<b; <1> This will output: 4 2. <0> yep <0> got it :) <1> What you jsut said would output 12. <3> You can do cout << (a << 1); I believe. <0> also <0> :) <0> can i ask more ? <1> You sure can. <1> We answer you long time. <3> lol <0> & <0> :) <3> Might I suggest you read: http://www.cprogramming.com/tutorial/bitwise_operators.html <0> & is bitwise related too ? <3> By itself, yes. <0> ^ <3> & >> << | ^ <0> and | <0> also ? <3> Yes. <0> ah <0> great. now that makes things simple :) <3> Just remember that && is different from & and such. <0> oh ? <2> & is the worst thig in c/c++ <2> thing. <2> it has 3 distinct and unrelated meanings <3> && is logical AND while & is bitwise. <1> And ~. Don't forget ~. <1> & has 3 distinct meanings& <1> ? <0> these are all related with what they call as "operators" right ? <1> What would they be, except from bitwise and? <3> Yes NrGSTaR <0> :) <0> Pretty simple, only I guess I'll have to look for excersises from the web. <0> that makes the best practice. instead of theory. <0> you guys, hmm think that I could learn functions in a few hours ? :) <0> its not that complicated if explained well, no ? <2> DrkMatter: let's see, taking an address maybe ? <2> and for references <2> NrGSTaR : all of these special symbols that have meanings (including +, ==, etc) are called operators <2> they are actually simple just function, with a nice way to call them <0> ok
<0> so <0> a++ would be a+1, right ? <2> not quite <2> a++ both increases a, and returns it's value before the increase <2> so b = a++ is the same as b = a; a = a+1; <2> just a++ is the same as a+=1 which is the same as a=a+1 <0> a=1; a++, would result 2? <2> after both expressions the value of a would be 2, right <2> here's a tricky one : a = 1; a+= a++ + ++a; <0> lets see <2> it's not quite defined in the standard what the value of a should be after this executes <2> so the point is - don't write stuff like that if you want to be sure what the program does :) <0> 4 ? <2> no way it can be 4, at least 5 <0> a++ would make 2. <0> then ++a would make what ? <2> but it doesn't matter - prefer simplier and more readable code <2> why do you ***ume it's calculated from left to right ? <0> I would, but when you're tested, they always make it treaky <0> ++a would be 1+a ? <2> ++a increases a, and returns the increased value. <2> a++ increases, but returns the previous value <2> a = 1; b = a++; // b = 1; a = 2 <2> a = 1; b = ++a; // b = 2; a = 2 <0> confusing. I'll read it a couple of more times :P <0> and then you can ask me a treaky question and i'll see if i got it <0> lets try <0> :) <0> ask me a treaky one :P <3> A really tricky one? :P <3> Or just tricky? <0> lets start from tricky <0> and go on to the real one :P <3> The real one is a trick question actually, :P <3> int a = 5; int b = a + a++; <3> What's b? <0> b=11 ? <3> 10 :p <0> or 10 <0> yes, because the value is the same, we didnt actually do anything. <3> a will then be 6 after that statement though. <3> But only after b= a + a++; <3> What about b = a++ + a; ? <0> b=6+5=11 <0> ? <4> allo <3> It's 10 still <3> :P <3> Here's a way of thinking about it, if you see a++, it won't actually change a until the statement is finished (look for a ;) <0> oh, so it was backwards. <0> but once the statement is finished a becomes a+1 <3> Yes <0> a=2, b=a++; <3> b = 2, a = 3 after <0> will result a=2, b=3, or b=a (which is 2) and a=3 <0> ah <0> :) <5> can someone help? <0> and a=2 b=++a, will result both to be 3 <3> Yes. <3> Now how about int a = 5; int b = ++a + a; <3> This one is tricky. <0> a=11, b=11 <3> Actually, a = 11, b = 12 <0> ah <3> Or sorry <0> yes, ok i think i got it. <3> a = 6 <3> a = 6, b = 12 <0> yes :) <0> b = 12 <0> ? <3> Yes <0> b = 6+6 ?
Return to
#c++ or Go to some related
logs:
#MissKitten #mirc #linux the kind you push in or andek brazilian #chatzone #chatzone awll3026 linux #squid #AllNiteCafe
|
|