preface

Writing articles have not said the habit of digress, just take advantage of this opportunity to chat. This series now update article 14, article seems very loose, but it has been the outline of the main line, was made up of the name “practice” Android, rather than a fine cross into small modules, it is really lazy, 2 it is, please feel free, always think that the scaffolding is too limited, writing like homework or not.

I also have a section of their own, like this article, very small, but in the previous article has always been involved, so I want to write, not so much to say and others say, as for their own, let yourself see the source code more relaxed point, this may be the purpose of the blog. It’s a blessing to help others while helping yourself.

I hope we can all in this society, not impatient, not lose themselves.

The body of the

The original code

Source code is a binary representation of a number in a computer, using the integers 5 and -5 as the digits, the first bit as the sign bit, 0 for positive and 1 for negative, as shown below:

Radix-minus-one complement

The inverse code of a positive number is the same as the original code, with the integer 5 as chestnut, see below:

The inverse of negative numbers is that the sign bits remain unchanged on the basis of the original code, and the other bits are reversed, taking the integer -5 as the example, as shown below:

complement

The complement of a positive number is the same as the original, with the integer 5 as the chestnut, as shown below:

The complement of a negative number is the inverse +1, the integer -5, as shown below:

<< (left shift)

The rules for positive and negative integers are the same: bits removed to the left are discarded and zeros are added to the right. In machines that use the complement as the number of machines, the integer 5 << 2 is chestnut:

If the rules for positive and negative integers are the same, -5 << 2 is used as the chestnut:

So the result is 5 << 2 = 20, -5 << 2 = -20, provided that the numbers do not overflow, at the number x << y = x * 2y2^y2y

>> (with sign moved right)

This operator moves the first operand to the right by the specified number of digits. The bits moved to the right are discarded and the leftmost bits are copied to fill the left, using the integer 5 >> 2 as an example:

Take the integer -5 >> 2 as an example:

>>> (unsigned right shift)

This operator moves the first operand to the right by the specified number of digits. Bits moved to the right are discarded and the left side is filled with zeros. Because the sign bit becomes zero, the result is always non-negative. For non-negative numbers, a signed right shift is the same as an unsigned right shift. 5 >>> 2 = 2 1^11+··+2 2^22 9^99

An operation

The rules of bitwise operation are shown below. It should be noted that bitwise and operation should also be performed in the form of complement code, and the result will be converted into our original code as above:

Well, this article is here, about the source code, inverse code, complement and bit operations are over. If this article is useful to you, give it a thumbs up. Everyone’s affirmation is also the motivation for Dumb I to keep writing.