Bit Manipulation: CORE CONCEPTS
Bit manipulation is a technique that involves directly manipulating the individual bits of a number. It's often used to optimize algorithms and solve problems efficiently.
BITWISE OPERATORS
Observations of XOR :
a ^ 1 = ā (compliment of a)
a ^ 0 = a
a ^ a = 0
Right Shift Operator [
\>>] -> shifts bits to the right , filling the vacant positions with zero(0).
General Point :
a >> b = a / (2^b)
Left Shift Operator [<<] -> Shifts bits to the left , filling the vacant positions with zero again.
General Point :
num << 1 == 2(num)
a << b = a (2^b)
Number System Conversion
The binary number system is a base-2 numeral system that uses only two digits, 0 and 1. This system is fundamental to modern computers and digital electronics because it's easy to represent with electrical signals (on/off, high/low voltage).
conversation steps :
Decimal to Base B
keep Diving by base , take the remainder ,Write in opposite
Base B to decimal
multiply and add the power of base with digits
int n =10;
System.out.println(Integer.toBinaryString(n));
Output :
1010
Negative of a Number
Take a compliment of that number
Add 1 to it
Most Significant Bit - Tells whether the number is +VE or -VE.
0 -> Negative
1-> Positive
Least Significant Bit - tells whether the number is ODD or EVEN.
0 -> EVEN
1 -> ODD
Range of Numbers
Range Formula :
Subscribe to my newsletter
Read articles from ANSH directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by