IRC log of #novawebdev for Monday, 2024-01-15

*** 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
ubuntouristhullo fkoikoi mulbah and tboimah 13:58
mulbahHello Mr. Cole13:58
tboimahGood morning ubuntorist13:58
fkoikoiHi Mr. Cole13:58
ubuntouristWe'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
gabrielHi cole13:59
ubuntouristhi gabriel 13:59
gabrielhow14:00
gabrielare you today14:00
ubuntouristgabriel, 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
ubuntouristBut, other than the first snowfall of the season, I'm doing great: Lots of fun making music with people.14:01
ubuntouristHow is everyone else?14:01
ubuntourist(How are all of you, I mean.)14:02
fkoikoinot bad14:02
gabrielmy bad but it's what it's so I think you might be use to it by now :_)14:02
mulbahI'm good Mr. Cole14:03
ubuntouristAny questions or things anyone wants to show off?14:04
gabrielnot really am trying to fix things by myself if i can't than i'll get to you14:08
ubuntouristgabriel, This is a good case for using git, I think. It will help you chart your progress through a problem.14:09
gabrielsure i gat a github account14:10
ubuntouristgabriel, (It really depends on how big the problem is: If you're just trying to understand something, then fooling around with Python interactively14:12
ubuntouristwill 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
ubuntouristNo 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 to14:15
ubuntouristcheck the manual pages to see how they work, because I don't use them often enough to remember.)14:15
ubuntouristOh, and init.14:16
gabrielyh i also use git clone to clone repo, git add, git commit -m to commit message that's all for now  14:16
gabrielalso git push14:17
fkoikoiMr. cole14:18
ubuntouristgabriel, pull is useful if you are collaborating -- usually if you're using clone, there is a strong possibility that you might collaborate.14:18
ubuntouristSo if you clone, get in the habit of using pull. 14:19
gabrielyah i did it once on a C printf function with my friend14:19
ubuntouristI cycle through pull, [edit], add, commit, push. And then repeat.14:19
ubuntouristfkoikoi, go ahead14:19
fkoikoiokay14:20
fkoikoican you talk a bit on the bitwise operator (or, xor, not) with the exception of &14:23
ubuntouristfkoikoi, Ooo bitwise Boolean stuff. Fun! ;-)14:24
ubuntouristfkoikoi, Since it's bitwise, the easiest thing to do is start with a single bit.14:24
ubuntouristfkoikoi, the simplest cocept is "NOT" -- but, it can also be the most confusing result.14:26
ubuntouristfkoikoi, Have you studied "twos-complement"?14:27
fkoikoino14:28
ubuntouristI'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
ubuntouristSo. A little explanation is in order. You all understand the basics of counting in binary, right? 14:29
ubuntouristI think you've all had a taste of that.14:29
gabrielwhat you mean by fool?14:29
gabrielsure14:30
fkoikoisure14:30
ubuntouristgabriel, I meant you have played with / experimented with.14:30
gabrielokay14:30
ubuntouristBut I'm guessing you have not done anything with NEGATIVE numbers in binary.14:31
gabrielsure only positive14:31
fkoikoino14:31
ubuntouristOK. 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
ubuntouristJeff can probably give you a more formal, mathematical definition, or you can investigate14:33
gabrielsure14:33
ubuntouriston your own, But, when you are talking about a single bit, the14:33
fkoikoiokay14:34
ubuntouristcomplement is the "opposite".  The compliment of 1 is 0 and the compliment of 0 is 1.14:34
ubuntouristSo NOT 1 = 0, and NOT 0 = 1.14:34
ubuntouristBut... in Python, if you type 14:35
ubuntouristx = 114:35
ubuntouristx = ~x14:35
ubuntouristprint(x)14:35
ubuntouristit gives an unexpected answer.14:35
gabriel214:35
ubuntouristgabriel, check again. Not quite right.14:36
gabriel-1-1=-214:36
ubuntourist(I mean "2" wasn't right.)14:37
gabrielyah the answer is -2 or negative 214:37
ubuntouristRight.14:37
ubuntouristWhen early programmers were trying to figure out how to make binary arithmatic work right,14:38
gabrielyah because from previous I learn that when you have a number ~n means you add negative 1 to that number14:39
ubuntouristgabriel, that is why I thought you might be ahead of other people on this. You have encountered some of this already.14:40
ubuntouristThe 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
ubuntouristThe problem is, if you do that, you end up with positive zero and negative zero which does not make sense.14:41
gabrielhahaha "sure"14:42
ubuntouristJust "flipping the bits" is called 1s-complement. flipping the bits and then adding 1 to the result is "2s-compliment".14:43
ubuntouristAn example:14:43
ubuntouristin the computer "1" in binary is really occupying several bits and you should think of it as 0000000000000000....0000114:44
gabrielokay14:44
ubuntouristWhen you type14:44
ubuntouristx = 114:44
ubuntouristx = ~x14:44
ubuntouristwhat really happens is that all  the zeros become ones and the 1s become 0s ....14:45
ubuntourist000000001 becomes 1111111111014:45
gabrielcan i ask?14:46
ubuntouristgabriel, sure.14:46
gabrieli 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
ubuntouristgabriel, 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
gabrielokay14:52
ubuntouristnegative numbers and logical NOT is used for a lot of things. Not just clearing memory.14:52
ubuntouristfkoikoi, I forgot to say that in Python "~x" means "NOT x" 14:53
gabrielokay maybe i didn't understand him too clear when he was presenting but i think i understood from you now14:53
fkoikoiyeah14:53
ubuntouristSo, back to binary math. First a little thing that will help a LOT:14:54
ubuntouristPython print formatting.14:54
ubuntouristThe newest and best way to print your answers in Python is to use f-string formatting. Try the following:14:55
ubuntouristx = 714:55
ubuntouristprint(f"x is equal to {x}")14:55
ubuntouristprint(f"x is equal to {x:b}")14:56
ubuntouristx = 25514:57
ubuntouristprint(f"x is equal to {x}")14:57
ubuntouristprint(f"x is equal to {x:f}")14:57
ubuntouristprint(f"x is equal to {x:x}")14:57
ubuntouristprint(f"x is equal to {x:o}")14:57
ubuntouristprint(f"x is equal to {x:b}")14:57
ubuntouristBe careful as you type. You may want to copy and paste.14:58
fkoikoiwhat is the b doing14:58
ubuntouristACTION needs to take a quick bathroom break. Think about it for a moment.14:58
gabrielam little bit lost can you please explain why it sum to 255?14:59
ubuntouristACTION is back15:01
ubuntouristgabriel, I wanted people to type "x = 255" and then the five print statements below it.15:02
ubuntouristfkoikoi, let's do it on the server....15:03
ubuntouristssh TSFX3TKjjzjnAgcYxC7r4vKLG@lon1.tmate.io15:03
fkoikoiokay15:03
ubuntourist(And, everybody, please keep your terminal window at 80 characters wide, 24 lines deep15:04
ubuntouristDON'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
ubuntouristSo 15:09
fkoikoiokay15:09
ubuntouristIn Python, we just saw several ways to show the same value.15:10
fkoikoiyeah but don't know what all of that means. I mean the (f, x, 0, b)15:11
ubuntouristI 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
ubuntouristfkoikoi, you should be able to figure it out some of that by the answers that it gave.15:12
fkoikoib print binary numbers right15:13
ubuntouristfkoikoi, right!15:13
ubuntouristfkoikoi, you can try in the terminal with a smaller number, like 15.15:13
ubuntouristType15:13
ubuntouristx = 1515:13
ubuntouristand then use the up-arrow to find the print statement you would like to see.15:14
ubuntourist(on the server)15:14
fkoikoisure15:14
gabrielyah it was i who ask that 15:15
ubuntouristfkoikoi, So, when you are trying to see what is happening when you use bitwise operators, you can use the f-string formatting15:16
ubuntouristto examine the results of your experiments.15:16
ubuntouristfkoikoi, do you see what the f, o, x and b are doing now?15:17
fkoikoiyes15:17
ubuntouristfkoikoi, great!15:17
ubuntouristI just typed in the terminal.15:19
ubuntouristPython is not smart enough -- or maybe it is too smart. Normally, when we are working with bitwise 15:20
ubuntouristcommands, we are not working with signed integers. The bits are not supposed to have a positive or negative.15:20
ubuntouristBut Python doesn't know that. So, it reinterprets the result as a signed integer..15:21
ubuntouristInstead of turning 1 into 0 with NOT, it turns 00000000001 to 11111111110 and then interprets it15:21
ubuntouristas a decimal signed integer.15:22
ubuntouristIn computer math, when you want to change an integer from positive to negative, or negative to positive,15:22
ubuntouristthink 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
ubuntouristAnyone 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
ubuntouristHint:15:24
tboimahACTION back I was run after something15:25
ubuntouristType 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
tboimahThe answer will be 0000101115:27
gabriel0010115:27
ubuntouristACTION needs to look for a detail about f-string formats. Hold a sec...15:28
gabrielok15:28
tboimahif 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 0000101115:29
tboimahthat is in eight bit15:30
fkoikoi0001111115:32
fkoikoioh15:32
ubuntouristACTION has found that python doesn't really handle unsigned integers well.15:32
ubuntouristSo getting print() to do what I want isn't as simple as I thought. But don't worry about that.15:33
fkoikoithat's the binary of 815:33
ubuntouristFirst, 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
ubuntouristLet me work with fkoikoi because she started with the question about bitwise operators.15:36
tboimahfirstly you will do the one complement15:36
ubuntouristtboimah, stop for a minute.15:36
tboimahnext you will to the two complement by adding plus 115:36
ubuntouristtboimah, STOP FOR A MINUTE!15:36
ubuntouristfkoikoi, So you walk through it with me. First, what is positive 5, in binary, with 8 bits?15:37
fkoikoi101 for positive 5 when using the print function15:38
ubuntouristfkoikoi, OK, but 8 bits please.15:39
ubuntouristfkoikoi, and don't rely on the print(). I want you to do the math and mental work of converting.15:39
fkoikoiokay15:40
fkoikoi1010 15:43
ubuntouristfkoikoi, You're still struggling with binary. The bitwise operators won't make sense until15:44
ubuntouristfkoikoi, you understand what I mean when I say "an 8-bit binary number"15:45
ubuntouristfkoikoi, 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
fkoikoisure15:47
fkoikoiI firstly divided 5 by two and left with the reminder 1 and 15:48
fkoikoiand divided two by two and got 0 as the reminder15:51
fkoikoithan i divided one by two and got 115:53
fkoikoii use the quotient as the dividend till i got 015:54
ubuntouristfkoikoi, 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
fkoikoiokay15: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
ubuntouristOK, now, with 8 bits that means "leading zeros" so 101 becomes:15:57
ubuntourist0000010115:57
ubuntouristNow, flip the bits. Zeros to ones. Ones to zeros.15:57
ubuntouristACTION waits for fkoikoi to type the flipped bits.15:57
fkoikoi1111101015:58
ubuntouristfkoikoi, Right. Now, add 1 to the result and type that.15:59
fkoikoi11111010116:00
ubuntouristfkoikoi, nope. I don't mean put an extra 1 on the end. I mean add. 11111010 + 1.16:01
fkoikoi2111101016:06
ubuntouristfkoikoi, Nope. tboimah's answer was ALMOST correct but the leading zeros aren't right.16:07
ubuntouristThink of it as:16:07
ubuntourist 1111101016:08
tboimahthe answer will be 1111101116:08
ubuntouristtboimah, I was typing...16:08
ubuntourist 1111101016:08
ubuntourist+0000000116:08
tboimahi just retify my mistake16:08
ubuntourist 1111101016:08
ubuntourist+0000000116:08
ubuntourist_________16:09
fkoikoii get it now16:10
ubuntouristBut 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
ubuntouristfkoikoi, OK good.16:10
ubuntouristI was hoping that Python would be a little better about showing you what happens with the NOT  bitwise operator.16:11
ubuntouristBut, very quickly, the other operators:16:11
ubuntourist101 & 010 = 000. For Bitwise AND, BOTH numbers must have 1 in the same position to get a 1 result.16:13
ubuntourist100 & 101 = 100. The highest order (leftmost) digit in both numbers is 1. True AND True = True. The next are 0 and 0.16:14
ubuntouristFalse 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
ubuntouristBitwise OR: We only need one "1" to make a 1 result.16:16
ubuntourist101 | 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 11116:17
ubuntouristBitwise XOR - Exclusive OR. You can ONLY have a single 1. Not both values being 1.16:18
ubuntourist101 ^ 111 = 010 -- 1 XOR 1 = 0. 0 XOR 1 = 1. 1 XOR 1 = 0. Final answer: 01016:19
ubuntouristI 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
ubuntouristEspecially when you try to verify the results by printing. Ideally, if I typed16:22
ubuntouristx = 116:22
ubuntouristx = ~x16:22
ubuntouristprint(x)16:22
ubuntouristI would want to see "0" as an answer. But, because Python cannot know we are not talking about regular integers, it chooses to16:23
ubuntouristshow 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 math16: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
ubuntourist11111110 flip16:26
ubuntourist00000001 and add 116:26
ubuntourist0000001016:26
ubuntouristwhich is a decimal 2. Therefore, when you say 'NOT 1' I answer '-2' instead of "0".)16:27
ubuntouristThat can be very confusing.16:27
*** mulbah has quit (Ping timeout: 480 seconds)16:28
ubuntouristExperiment using the f-strings. Also, you can assign binary, octal and hex values to to variables. Try experiments like:16:28
ubuntouristx = 0b10111010010     # or any 0b followed by any binary number16:29
ubuntouristx = 0xFF0B9AD    # or 0x followed by any hexadecimal digits16:30
ubuntouristx 0o12376534     # or 0o followed by octal digits16:30
ubuntouristtogether with the f-string 16:32
ubuntouristf"...{x:o}, {x:f}, {x:b}, {x:x}"16:32
ubuntouristyou 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
ubuntouristI hope that's not too much too fast.16:33
ubuntouristQuestions?16:33
ubuntourist(It's been a longer session than usual. So type fast. ;-)  )16:33
fkoikoino16:33
fkoikoisure, understood 16:33
fkoikoithanks for all16:34
fkoikoino questions for now16:35
ubuntouristGreat! Bitwise operators can save you a lot when you have many  conditions that you want to check.16:35
ubuntouristBye for now everybody.16:35
fkoikoiokay16:35
fkoikoisee you on Friday16:35
gabrielok thanks for the time, see you on friday16: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/!