*** shmohamud has quit (Ping timeout: 480 seconds) | 00:06 | |
*** shmohamud has quit (Remote host closed the connection) | 02:16 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 02:45 | |
*** shmohamud has quit (Remote host closed the connection) | 09:11 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 11:19 | |
*** dcammue has quit (Read error: Connection reset by peer) | 13:26 | |
ubuntourist | hullo fkoikoi mulbah and tboimah | 13:58 |
---|---|---|
mulbah | Hello Mr. Cole | 13:58 |
tboimah | Good morning ubuntorist | 13:58 |
fkoikoi | Hi Mr. Cole | 13:58 |
ubuntourist | We're having our first snow of the year. I moved south because I hated snow when I was growing up. I still hate snow. | 13:59 |
gabriel | Hi cole | 13:59 |
ubuntourist | hi gabriel | 13:59 |
gabriel | how | 14:00 |
gabriel | are you today | 14:00 |
ubuntourist | gabriel, I was just complaining about how I hate snow. Fortunately, in DC it rarely becomes a heavy snow like what I grew up with. | 14:01 |
ubuntourist | But, other than the first snowfall of the season, I'm doing great: Lots of fun making music with people. | 14:01 |
ubuntourist | How is everyone else? | 14:01 |
ubuntourist | (How are all of you, I mean.) | 14:02 |
fkoikoi | not bad | 14:02 |
gabriel | my bad but it's what it's so I think you might be use to it by now :_) | 14:02 |
mulbah | I'm good Mr. Cole | 14:03 |
ubuntourist | Any questions or things anyone wants to show off? | 14:04 |
gabriel | not really am trying to fix things by myself if i can't than i'll get to you | 14:08 |
ubuntourist | gabriel, This is a good case for using git, I think. It will help you chart your progress through a problem. | 14:09 |
gabriel | sure i gat a github account | 14:10 |
ubuntourist | gabriel, (It really depends on how big the problem is: If you're just trying to understand something, then fooling around with Python interactively | 14:12 |
ubuntourist | will probably be enough. But it's good to find excuses to practice git, because it's going to become something you'll all need to have basic fluency with.) | 14:13 |
ubuntourist | No need for everyone to become a super-expert, but clone, pull, add, commit, push, diff, log, and status should all become your friends. ;-) | 14:14 |
ubuntourist | (Those are the git commands I use ALL the time. Other commands I use rarely, and always need to | 14:15 |
ubuntourist | check the manual pages to see how they work, because I don't use them often enough to remember.) | 14:15 |
ubuntourist | Oh, and init. | 14:16 |
gabriel | yh i also use git clone to clone repo, git add, git commit -m to commit message that's all for now | 14:16 |
gabriel | also git push | 14:17 |
fkoikoi | Mr. cole | 14:18 |
ubuntourist | gabriel, pull is useful if you are collaborating -- usually if you're using clone, there is a strong possibility that you might collaborate. | 14:18 |
ubuntourist | So if you clone, get in the habit of using pull. | 14:19 |
gabriel | yah i did it once on a C printf function with my friend | 14:19 |
ubuntourist | I cycle through pull, [edit], add, commit, push. And then repeat. | 14:19 |
ubuntourist | fkoikoi, go ahead | 14:19 |
fkoikoi | okay | 14:20 |
fkoikoi | can you talk a bit on the bitwise operator (or, xor, not) with the exception of & | 14:23 |
ubuntourist | fkoikoi, Ooo bitwise Boolean stuff. Fun! ;-) | 14:24 |
ubuntourist | fkoikoi, Since it's bitwise, the easiest thing to do is start with a single bit. | 14:24 |
ubuntourist | fkoikoi, the simplest cocept is "NOT" -- but, it can also be the most confusing result. | 14:26 |
ubuntourist | fkoikoi, Have you studied "twos-complement"? | 14:27 |
fkoikoi | no | 14:28 |
ubuntourist | I'm guessing gabriel might have fooled with it because he's fooled around with C code, but I'm guessing everyone else has not. | 14:28 |
ubuntourist | So. A little explanation is in order. You all understand the basics of counting in binary, right? | 14:29 |
ubuntourist | I think you've all had a taste of that. | 14:29 |
gabriel | what you mean by fool? | 14:29 |
gabriel | sure | 14:30 |
fkoikoi | sure | 14:30 |
ubuntourist | gabriel, I meant you have played with / experimented with. | 14:30 |
gabriel | okay | 14:30 |
ubuntourist | But I'm guessing you have not done anything with NEGATIVE numbers in binary. | 14:31 |
gabriel | sure only positive | 14:31 |
fkoikoi | no | 14:31 |
ubuntourist | OK. This is where 2s-compliment arithmatic becomes something to learn. | 14:32 |
ubuntourist | "Compliment" has a different meaning in binary math than it does in English. | 14:33 |
ubuntourist | Jeff can probably give you a more formal, mathematical definition, or you can investigate | 14:33 |
gabriel | sure | 14:33 |
ubuntourist | on your own, But, when you are talking about a single bit, the | 14:33 |
fkoikoi | okay | 14:34 |
ubuntourist | complement is the "opposite". The compliment of 1 is 0 and the compliment of 0 is 1. | 14:34 |
ubuntourist | So NOT 1 = 0, and NOT 0 = 1. | 14:34 |
ubuntourist | But... in Python, if you type | 14:35 |
ubuntourist | x = 1 | 14:35 |
ubuntourist | x = ~x | 14:35 |
ubuntourist | print(x) | 14:35 |
ubuntourist | it gives an unexpected answer. | 14:35 |
gabriel | 2 | 14:35 |
ubuntourist | gabriel, check again. Not quite right. | 14:36 |
gabriel | -1-1=-2 | 14:36 |
ubuntourist | (I mean "2" wasn't right.) | 14:37 |
gabriel | yah the answer is -2 or negative 2 | 14:37 |
ubuntourist | Right. | 14:37 |
ubuntourist | When early programmers were trying to figure out how to make binary arithmatic work right, | 14:38 |
gabriel | yah because from previous I learn that when you have a number ~n means you add negative 1 to that number | 14:39 |
ubuntourist | gabriel, that is why I thought you might be ahead of other people on this. You have encountered some of this already. | 14:40 |
ubuntourist | The original thought was "Just add add an extra bit that represents the sign" in the same way that we just include a "-" to inicate negative. | 14:41 |
ubuntourist | The problem is, if you do that, you end up with positive zero and negative zero which does not make sense. | 14:41 |
gabriel | hahaha "sure" | 14:42 |
ubuntourist | Just "flipping the bits" is called 1s-complement. flipping the bits and then adding 1 to the result is "2s-compliment". | 14:43 |
ubuntourist | An example: | 14:43 |
ubuntourist | in the computer "1" in binary is really occupying several bits and you should think of it as 0000000000000000....00001 | 14:44 |
gabriel | okay | 14:44 |
ubuntourist | When you type | 14:44 |
ubuntourist | x = 1 | 14:44 |
ubuntourist | x = ~x | 14:44 |
ubuntourist | what really happens is that all the zeros become ones and the 1s become 0s .... | 14:45 |
ubuntourist | 000000001 becomes 11111111110 | 14:45 |
gabriel | can i ask? | 14:46 |
ubuntourist | gabriel, sure. | 14:46 |
gabriel | i follow David malan on cs50 and on one of his teaching he said that we only do this when we're getting raid of memory where we change 0s to 1s and 1s to 0s at bit level so how is it possible because in doing we'll consume more of the cpu | 14:49 |
ubuntourist | gabriel, I think I will need to read what David Malan is saying. I am not sure what he means by "we only do this when we're getting rid? of memory". | 14:51 |
gabriel | okay | 14:52 |
ubuntourist | negative numbers and logical NOT is used for a lot of things. Not just clearing memory. | 14:52 |
ubuntourist | fkoikoi, I forgot to say that in Python "~x" means "NOT x" | 14:53 |
gabriel | okay maybe i didn't understand him too clear when he was presenting but i think i understood from you now | 14:53 |
fkoikoi | yeah | 14:53 |
ubuntourist | So, back to binary math. First a little thing that will help a LOT: | 14:54 |
ubuntourist | Python print formatting. | 14:54 |
ubuntourist | The newest and best way to print your answers in Python is to use f-string formatting. Try the following: | 14:55 |
ubuntourist | x = 7 | 14:55 |
ubuntourist | print(f"x is equal to {x}") | 14:55 |
ubuntourist | print(f"x is equal to {x:b}") | 14:56 |
ubuntourist | x = 255 | 14:57 |
ubuntourist | print(f"x is equal to {x}") | 14:57 |
ubuntourist | print(f"x is equal to {x:f}") | 14:57 |
ubuntourist | print(f"x is equal to {x:x}") | 14:57 |
ubuntourist | print(f"x is equal to {x:o}") | 14:57 |
ubuntourist | print(f"x is equal to {x:b}") | 14:57 |
ubuntourist | Be careful as you type. You may want to copy and paste. | 14:58 |
fkoikoi | what is the b doing | 14:58 |
ubuntourist | ACTION needs to take a quick bathroom break. Think about it for a moment. | 14:58 |
gabriel | am little bit lost can you please explain why it sum to 255? | 14:59 |
ubuntourist | ACTION is back | 15:01 |
ubuntourist | gabriel, I wanted people to type "x = 255" and then the five print statements below it. | 15:02 |
ubuntourist | fkoikoi, let's do it on the server.... | 15:03 |
ubuntourist | ssh TSFX3TKjjzjnAgcYxC7r4vKLG@lon1.tmate.io | 15:03 |
fkoikoi | okay | 15:03 |
ubuntourist | (And, everybody, please keep your terminal window at 80 characters wide, 24 lines deep | 15:04 |
ubuntourist | DON'T play with resizing the window.) | 15:04 |
ubuntourist | (It messes the sharing of the window if you are all constantly readjusting the window size.) | 15:05 |
ubuntourist | So | 15:09 |
fkoikoi | okay | 15:09 |
ubuntourist | In Python, we just saw several ways to show the same value. | 15:10 |
fkoikoi | yeah but don't know what all of that means. I mean the (f, x, 0, b) | 15:11 |
ubuntourist | I don't know who asked the question, but ":x" prints the hex value in lower case. ":X" prints the hex value in upper case. | 15:11 |
ubuntourist | fkoikoi, you should be able to figure it out some of that by the answers that it gave. | 15:12 |
fkoikoi | b print binary numbers right | 15:13 |
ubuntourist | fkoikoi, right! | 15:13 |
ubuntourist | fkoikoi, you can try in the terminal with a smaller number, like 15. | 15:13 |
ubuntourist | Type | 15:13 |
ubuntourist | x = 15 | 15:13 |
ubuntourist | and then use the up-arrow to find the print statement you would like to see. | 15:14 |
ubuntourist | (on the server) | 15:14 |
fkoikoi | sure | 15:14 |
gabriel | yah it was i who ask that | 15:15 |
ubuntourist | fkoikoi, So, when you are trying to see what is happening when you use bitwise operators, you can use the f-string formatting | 15:16 |
ubuntourist | to examine the results of your experiments. | 15:16 |
ubuntourist | fkoikoi, do you see what the f, o, x and b are doing now? | 15:17 |
fkoikoi | yes | 15:17 |
ubuntourist | fkoikoi, great! | 15:17 |
ubuntourist | I just typed in the terminal. | 15:19 |
ubuntourist | Python is not smart enough -- or maybe it is too smart. Normally, when we are working with bitwise | 15:20 |
ubuntourist | commands, we are not working with signed integers. The bits are not supposed to have a positive or negative. | 15:20 |
ubuntourist | But Python doesn't know that. So, it reinterprets the result as a signed integer.. | 15:21 |
ubuntourist | Instead of turning 1 into 0 with NOT, it turns 00000000001 to 11111111110 and then interprets it | 15:21 |
ubuntourist | as a decimal signed integer. | 15:22 |
ubuntourist | In computer math, when you want to change an integer from positive to negative, or negative to positive, | 15:22 |
ubuntourist | think of the binary, and change all 0's to 1's and all 1's to 0's and THEN add 1 to the result. | 15:23 |
ubuntourist | Anyone except gabriel (because he already knows some of this): In binary, using 8 bits type the value of -5. (Wait for the hint) | 15:24 |
ubuntourist | Hint: | 15:24 |
tboimah | ACTION back I was run after something | 15:25 |
ubuntourist | Type the eight bits for positive 5. Then do what I said: Flip the 0's and 1's and add 1 to the result and show the 8 bits. | 15:25 |
tboimah | The answer will be 00001011 | 15:27 |
gabriel | 00101 | 15:27 |
ubuntourist | ACTION needs to look for a detail about f-string formats. Hold a sec... | 15:28 |
gabriel | ok | 15:28 |
tboimah | if you need the value for positive 5 in binary it will be 00000101 but if you need the value for negative 5 it will be 00001011 | 15:29 |
tboimah | that is in eight bit | 15:30 |
fkoikoi | 00011111 | 15:32 |
fkoikoi | oh | 15:32 |
ubuntourist | ACTION has found that python doesn't really handle unsigned integers well. | 15:32 |
ubuntourist | So getting print() to do what I want isn't as simple as I thought. But don't worry about that. | 15:33 |
fkoikoi | that's the binary of 8 | 15:33 |
ubuntourist | First, tboimah no: The rules for conversion betweeen negative and positive are "flip the bits" then at 1. You did not do that. You are close though. | 15:35 |
ubuntourist | Let me work with fkoikoi because she started with the question about bitwise operators. | 15:36 |
tboimah | firstly you will do the one complement | 15:36 |
ubuntourist | tboimah, stop for a minute. | 15:36 |
tboimah | next you will to the two complement by adding plus 1 | 15:36 |
ubuntourist | tboimah, STOP FOR A MINUTE! | 15:36 |
ubuntourist | fkoikoi, So you walk through it with me. First, what is positive 5, in binary, with 8 bits? | 15:37 |
fkoikoi | 101 for positive 5 when using the print function | 15:38 |
ubuntourist | fkoikoi, OK, but 8 bits please. | 15:39 |
ubuntourist | fkoikoi, and don't rely on the print(). I want you to do the math and mental work of converting. | 15:39 |
fkoikoi | okay | 15:40 |
fkoikoi | 1010 | 15:43 |
ubuntourist | fkoikoi, You're still struggling with binary. The bitwise operators won't make sense until | 15:44 |
ubuntourist | fkoikoi, you understand what I mean when I say "an 8-bit binary number" | 15:45 |
ubuntourist | fkoikoi, first, can you explain why 101 bnary is equal to 5 decimal? What is the value of the each of the three bits? | 15:46 |
fkoikoi | sure | 15:47 |
fkoikoi | I firstly divided 5 by two and left with the reminder 1 and | 15:48 |
fkoikoi | and divided two by two and got 0 as the reminder | 15:51 |
fkoikoi | than i divided one by two and got 1 | 15:53 |
fkoikoi | i use the quotient as the dividend till i got 0 | 15:54 |
ubuntourist | fkoikoi, Good. But, you will become faster if you can think in powers of 2. 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096... | 15:55 |
fkoikoi | okay | 15:56 |
ubuntourist | (I usually don't need to remember much farther than 4096, but getting up to 2 to the 16th power can be useful.) | 15:56 |
ubuntourist | OK, now, with 8 bits that means "leading zeros" so 101 becomes: | 15:57 |
ubuntourist | 00000101 | 15:57 |
ubuntourist | Now, flip the bits. Zeros to ones. Ones to zeros. | 15:57 |
ubuntourist | ACTION waits for fkoikoi to type the flipped bits. | 15:57 |
fkoikoi | 11111010 | 15:58 |
ubuntourist | fkoikoi, Right. Now, add 1 to the result and type that. | 15:59 |
fkoikoi | 111110101 | 16:00 |
ubuntourist | fkoikoi, nope. I don't mean put an extra 1 on the end. I mean add. 11111010 + 1. | 16:01 |
fkoikoi | 21111010 | 16:06 |
ubuntourist | fkoikoi, Nope. tboimah's answer was ALMOST correct but the leading zeros aren't right. | 16:07 |
ubuntourist | Think of it as: | 16:07 |
ubuntourist | 11111010 | 16:08 |
tboimah | the answer will be 11111011 | 16:08 |
ubuntourist | tboimah, I was typing... | 16:08 |
ubuntourist | 11111010 | 16:08 |
ubuntourist | +00000001 | 16:08 |
tboimah | i just retify my mistake | 16:08 |
ubuntourist | 11111010 | 16:08 |
ubuntourist | +00000001 | 16:08 |
ubuntourist | _________ | 16:09 |
fkoikoi | i get it now | 16:10 |
ubuntourist | But since tboimah has given away the answer, I guess you won't be able to figure it out by yourself as I had hoped. | 16:10 |
ubuntourist | fkoikoi, OK good. | 16:10 |
ubuntourist | I was hoping that Python would be a little better about showing you what happens with the NOT bitwise operator. | 16:11 |
ubuntourist | But, very quickly, the other operators: | 16:11 |
ubuntourist | 101 & 010 = 000. For Bitwise AND, BOTH numbers must have 1 in the same position to get a 1 result. | 16:13 |
ubuntourist | 100 & 101 = 100. The highest order (leftmost) digit in both numbers is 1. True AND True = True. The next are 0 and 0. | 16:14 |
ubuntourist | False AND False = False. The final digits are 0 and 1. False AND True = False. So the answer is True False False or 100. | 16:15 |
ubuntourist | Bitwise OR: We only need one "1" to make a 1 result. | 16:16 |
ubuntourist | 101 | 010 = 111. Bitwise OR. There is at least a 1 in every position somewhere. 1 OR 1 = 1, 0 OR 1 = 1, 1 OR 1 = 1. Final result 111 | 16:17 |
ubuntourist | Bitwise XOR - Exclusive OR. You can ONLY have a single 1. Not both values being 1. | 16:18 |
ubuntourist | 101 ^ 111 = 010 -- 1 XOR 1 = 0. 0 XOR 1 = 1. 1 XOR 1 = 0. Final answer: 010 | 16:19 |
ubuntourist | I know I rushed through that last part. We spent a lot of time on NOT (~) because of its relationship to negative (-) can make life very confusing. | 16:21 |
ubuntourist | Especially when you try to verify the results by printing. Ideally, if I typed | 16:22 |
ubuntourist | x = 1 | 16:22 |
ubuntourist | x = ~x | 16:22 |
ubuntourist | print(x) | 16:22 |
ubuntourist | I would want to see "0" as an answer. But, because Python cannot know we are not talking about regular integers, it chooses to | 16:23 |
ubuntourist | show the results as a signed value. It "sees" 1 as "00000001" and then uses the ~ to change it to "111111110" and then uses 2s-complement math | 16:24 |
ubuntourist | "Hmmm. It starts with a 1 on the left. Therefore, I interpret it as negative. I will print a minus symbol and use 2s-compliment to turn it back into a positive value: | 16:25 |
ubuntourist | 11111110 flip | 16:26 |
ubuntourist | 00000001 and add 1 | 16:26 |
ubuntourist | 00000010 | 16:26 |
ubuntourist | which is a decimal 2. Therefore, when you say 'NOT 1' I answer '-2' instead of "0".) | 16:27 |
ubuntourist | That can be very confusing. | 16:27 |
*** mulbah has quit (Ping timeout: 480 seconds) | 16:28 | |
ubuntourist | Experiment using the f-strings. Also, you can assign binary, octal and hex values to to variables. Try experiments like: | 16:28 |
ubuntourist | x = 0b10111010010 # or any 0b followed by any binary number | 16:29 |
ubuntourist | x = 0xFF0B9AD # or 0x followed by any hexadecimal digits | 16:30 |
ubuntourist | x 0o12376534 # or 0o followed by octal digits | 16:30 |
ubuntourist | together with the f-string | 16:32 |
ubuntourist | f"...{x:o}, {x:f}, {x:b}, {x:x}" | 16:32 |
ubuntourist | you can do all sorts of conversions. And you can experiment with ~, &, |, and ^ for NOT, AND, OR and XOR to become more comfortable with them. | 16:33 |
ubuntourist | I hope that's not too much too fast. | 16:33 |
ubuntourist | Questions? | 16:33 |
ubuntourist | (It's been a longer session than usual. So type fast. ;-) ) | 16:33 |
fkoikoi | no | 16:33 |
fkoikoi | sure, understood | 16:33 |
fkoikoi | thanks for all | 16:34 |
fkoikoi | no questions for now | 16:35 |
ubuntourist | Great! Bitwise operators can save you a lot when you have many conditions that you want to check. | 16:35 |
ubuntourist | Bye for now everybody. | 16:35 |
fkoikoi | okay | 16:35 |
fkoikoi | see you on Friday | 16:35 |
gabriel | ok thanks for the time, see you on friday | 16:40 |
*** gabriel has quit (Quit: Leaving) | 16:40 | |
*** fkoikoi has quit (Quit: Leaving) | 16:52 | |
*** ubuntourist has quit (Quit: Leaving) | 16:53 | |
*** tboimah has quit (Ping timeout: 480 seconds) | 17:09 | |
*** scooper has quit (Ping timeout: 480 seconds) | 17:09 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!