Bit operation correlation (2) - simple transformation operation of bit operation

Introduction What is Bitwise Operations?

Please refer to bit operation related (1) - bit operation study notes

First, the operation of the last bit

(1) Remove the last digit—— x>>1

(2) Increase the last digit - increase 0: x<<1 , increase 1: (x<<1)+1

(3) Change the last digit - change to 0: (x|1)-1 , change to 1: x|1 , negate: x^1

2. Operation on the kth bit of the right number

(1) Change to 0: x&~(1<<(k-1))

(2) Change to 1: x|(1<<(k-1))

(3) Negative: x^(1<<(k-1))

(4) Take the kth digit from the right: (x>>(k-1))&1

Third, the operation of the last k bits

(1) Change to 1: x|((1<<k)-1)

(2) Negative: x^((1<<k)-1)

(3) Take the last k bits: x&((1<<k)-1)




Note: If you have learned the simple transformation operation of bit operation through this article, please like and leave. Of course, you are also welcome to point out the shortcomings of this article in the discussion area. The author will correct this article in time
. Copyright statement: Please indicate the address for reprinting

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325756264&siteId=291194637