0

Python challenge x = ~3

There's a challenge where "x =~3, y = 5, x * y = - 20". What does "x =~3" mean? How do we get result of "- 20"?

8th Sep 2020, 7:12 AM
Anton
5 ответов
+ 2
Formula of find bitwise complement x=-(x+1) Here x = 3 So bitwise compliment is -(x+1) => x=-(3+1) => x=-4 x*y=-4*3 So answer will be -12 https://www.sololearn.com/learn/4076/?ref=app
8th Sep 2020, 7:34 AM
Vadivelan
+ 5
Are you sure the answer is -20? I think the answer is -12. I think the code will something like this (might be wrong because I don't know Python) https://code.sololearn.com/coCkHTKIbfm2/?ref=app
8th Sep 2020, 7:28 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
~ is the NOT bitwise operator. In my opinion the logics behind it, is one of the most difficult to understand. Bitwise operator are operators used to perform bitwise operations (on integers converted to binary, bit by bit). The not operator "inverts all the bits". For example: >>>~3 # 3 is first converted to binary --> 11 (0b11) # then it is inverted and 1 is added to it (I'll search for additional information in a minute): 0b11 --> -(0b11 +0b1) --> -(0b100) --> -0b100 # then the binary is converted to decimal again --> -4 Is it not possible the "-20" result, given an y of 3. In this case x*y = -12 y should be 5 to have the result of -20. https://www-geeksforgeeks-org.cdn.ampproject.org/v/s/www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-bitwise-operators/amp/?amp_js_v=a2&amp_gsa=1&usqp=mq331AQFKAGwASA%3D#aoh=15995500141265&amp_ct=1599550018523&referrer=https%3A%2F%2Fwww.google.com&amp_tf=%D0%94%D0%B6%D0%B5%D1%80%D0%B5%D0%BB%D0%BE%3A%20%251%24s&ampshare=https%3A%2F%2Fwww.geeksforgeeks.org%2Fpython-bitwise-operators%2F
8th Sep 2020, 7:49 AM
Феникс
Феникс - avatar
8th Sep 2020, 7:49 AM
Феникс
Феникс - avatar