Today we will study Bit manipulation, Bit magic and Bitwise operators. Bits are actually very important
from Competitive programming point of view. If your submission differs by just a few microseconds,
then it affects your rank as well. If you would be using BITWISE concepts, then your submission will be
very fast. We will learn such tips and tricks in bits.
You can convert any decimal number to binary using this method. Addition/subtraction works in the
same way as they work in decimal numbers. In binary numbers, digits are from 0-9 but they go from 0 to
1 in binary numbers. You will get used to it when you practice it more, so this is how your binary number
works. The main question is how to find the negative inverse of any number in binary is 2 's compliment.
Negative inverse of a number which we have to subtract and then we will add it to the other number to
get our answer. The last carry will keep on making all the extra set bits as 0 and this carry will be
discarded.
In microprocessors, all the additions/subtractions are done using this way only There is no operation as
Subtraction. We find the 2 's compliment and then add it with the other number. You just have to
inverse all the bits and add 1. The right shift operator shifts the bits towards right. We use tilt (~) symbol
to present inverse operation. We have left shift operator. When you have to perform left shift by 2, then
you will shift all the bits towards left by 2 and it will get converted to this. We can replace the empty bits
with zeroes. This number equals 48. We can use it whenever we need to divide a number by 2 multiple
times. This is how we use to find whether a number is ODD or even. The power of the XOR operator is a
very simple concept by computationally it is a bit faster.