+ 4
What is ~ ?
In quiz rating I found: x=~3 y=5 print(x*y) So I made this code but I still dont know what it is "~" https://code.sololearn.com/cBV4zBBVPT2O/?ref=app
8 Respostas
+ 8
It's the Bitwise Complement operator.
https://www.sololearn.com/learn/4076/
+ 7
an int is a number that is not a decimal
+ 4
~ x
Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1.
This operator takes a number’s binary, and returns its one’s complement. For this, it flips the bits until it reaches the first 0 from right.
https://code.sololearn.com/cv5I6VanqJWD
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
i binary(i) binary(~i) ~i
0 0000 -001 -1
1 0001 -010 -2
2 0010 -011 -3
3 0011 -100 -4
4 0100 -101 -5
5 0101 -110 -6
6 0110 -111 -7
7 0111 -1000 -8
8 1000 -1001 -9
9 1001 -1010 -10
+ 3
JT JT I mean what is "~"
+ 2
Thx
+ 2
It is actually the Bitwise Complement operator.
Check ot pit here(Learn About It)-
https://www.sololearn.com/learn/4076/
+ 2
It's used as a "reverse" or "opposite" opperation for integers. So say x = 3, and then we do ~x, thats equivalent to -3
+ 1
Actuall it does this
number = -number - 1
If the number is positive number it will turn it to negative and subtract 1 from it.
If the number is negative number it will turn it into a positive number then subtract 1 from it.