Home > database >  The questions in python
The questions in python

Time:09-28

Why python efficiency is not high
Why python ~ 1=2

CodePudding user response:

Because he use C, run slow, are ready-made method, it is convenient,

CodePudding user response:

Is the ~ n=- (n + 1)

CodePudding user response:

In python, use the not symbol ~ get the result is not our imagination, summarize the rule, is (after invert value)=- (value) before the not - 1

Below to analyze, such as to take the 1, one of eight binary representation is: 0000 0001, take the result is: after 1111, 1110, for the computer, the binary begin with 1 said is negative, so the 1111 1110 what is negative, want to know the value, ask its complement, namely first take radix-minus-one complement: 0000, 0001, 0010, 00 plus 1 p.m. shows the original code, 1111, 1110 to 0000, 0010 is a positive number 2, so representative is a negative number, 1111, 1110-2

Here to give you an example: to take anti - 2, 2 for 2's complement binary representation, namely, 0000, 0010 & gt; 1111, 1101 & gt; 1111, 1110-2 binary is represented as a 1111, 1110, on it get 0000, 0001, it is obvious that after taking the value is 1, so ~ (2)=1, 2
~ 1=-
Is concluded: (after invert value)=- (take the former value) - 1
  • Related