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"?
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
+ 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
+ 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&_gsa=1&usqp=mq331AQFKAGwASA%3D#aoh=15995500141265&_ct=1599550018523&referrer=https%3A%2F%2Fwww.google.com&_tf=%D0%94%D0%B6%D0%B5%D1%80%D0%B5%D0%BB%D0%BE%3A%20%251%24s&share=https%3A%2F%2Fwww.geeksforgeeks.org%2Fpython-bitwise-operators%2F
+ 1