Binary bitwise operators &&

Bitwise
between binary and decimal conversion
. A decimal -> Binary
addition operation 2 until addition until 0, the reverse is the remainder obtained corresponding to the decimal binary
byte 1 byte 8 bits (binary digits)
2 16 Short
int. 4 32
Long. 8 bit 64
byte B = 2;
2 -> 10
3 ->. 11
15 -> 1111
13 is -> 1101
B binary -> decimal.
1011-->. 11
2 3 * ^ 2 + 1 ^ 2 + 2 ^ 0 * 1 * 1 * 1 + 0 2 ^
8 + 0 + 2 + 1
11001 -> 25
2 + 1 ^ 2 ^ 4 * 3 * 2 * 1 + 0 + 2 ^ 2 ^ 1 * 0 + 2 ^ 0 *
16 + 8 + 0 + 0 + 1 25
32 16 8. 4 2 1
highest bit is a sign bit 0 positive 1 negative
original code: 10001111
anti-code: 11110000
original code representation in front of the numerical value increases a sign bit (i.e., the highest bit is the sign bit): this bit is a positive number of 0, the bit is a negative number (0 has two representations: +0 and -0),
the remaining bits represent the magnitude of the value.
For example, represents a binary number of 8-bit, the original code is 00001011 + 11, -11 of the original code is 10001011.

Anti predetermined code notation: positive anti-code the same as their original code; negative inverted by the original code is its bit inverse, except for the sign bit.
Complement notation provides: a positive number of the same complement of its original code; negative complement thereof is incremented by 1 in the inverted (inverted original code bit by bit) of the last.

3. bitwise
after << shift, gap fill 0, discards the removed high, empty bit 0s. M << n fact, such a calculation may be M * = M << n ^ n-2
>> highest binary 0 is shifted, the right, up empty bit 0; M >> n = M / 2 ^ n n the number of anti-code complement the original code consistent with
the most significant bit is 1, 1 fill vacant position.
-1510001111
inverted 11110000
complement 11110001
right three 11111110

Complement 1 1 1 1 1 1 0 1
inverted 0 0 0 0 0 1 0 1
>> 2 stars -2
>>> most significant bit is shifted either binary 0 or 1, with 0 bits are fill vacancies. If the positive fact be so considered M << n = M * 2 ^ n negative becomes a big positive
& binary bits & operation, only 1 & 1 result is 1, otherwise 0;
| binary bits | computing only 0 | 0 the result is 0, 1 otherwise;
^ ^ same binary bit operation, the result is 0; 1 ^ 1 = 0, 0 ^ 0 = 0
is not the same operation result is a bit ^ 1.1 ^ 0 = 1, 0 1 = 1 ^
- positive negated, each of the binary codes in two's complement (in this case a positive integer) Members negated (becomes negative integer), supplemented code
(complement negative integers not the original code symbol bits change, first subtracting the original code 1, the last bit value you inversion)
~ 1500001111
inverted == 00001111
complement == 0000111 1
negated ~ 11110000
----------------------------------
complement -1 11101111
inverted ~ 10010000
primitive -2 ^ 4 = -16
seeking complement negative integers, the original code symbol bits unchanged, first subtracting the original code 1, Finally, I take anti-bit value.
(However, due to the special nature of binary, typically first make you inverted bit values, and finally the whole number plus 1)
follows the same results
~ 1500001111
inverted == 00001111
complement == 00001111
inverted to 1. 1. 1. 1 0 0 0 0
----- -----------------------------
value bit inversion 10001111
+1 1001000 0 == -16

negative inverse of the binary codes in each of the inverted complement you, (but the same number of positive original code and its complement) supplemented code
-3410100010
inverted 1101 1101
complement 11011110
negated 00100001 == 33

Guess you like

Origin www.cnblogs.com/Lovemeifyoudare/p/11440350.html