✨Introduction
-> Bitwise Operations let you manipulate numbers at bit level. Bitwise operations are faster than regular operations.
There are main 6 bitwise operators:
1)Bitwise AND
2)Bitwise OR
3)Bitwise XOR
4)Bitwise left-shift
5)Bitwise right-shift
6)Bitwise complement
✨Bitwise AND
-> The Bitwise AND tests 2 binary numbers and returns bit values of 1 for positions where both numbers had a one, and a bit value of 0 at every other position.
Symbol- '&' (for C++, Java, Python, JavaScrpit)
✨Example of Bitwise AND
✨Bitwise OR
-> The Bitwise OR tests 2 binary numbers and returns a bit value of 0 for positions where both bits are 0, and a bit value of 1 at every other position.
Symbol- '|' (for C++, Java, Python, JavaScrpit)
✨Example of Bitwise OR
✨Bitwise XOR
-> The Bitwise XOR(Exclusive-OR) tests two binary numbers and returns bit values of 1 for positions where both bits are different; if they are the same then the result is 0.
Symbol- '^' (for C++, Java, Python, JavaScrpit)
✨Example of Bitwise XOR
✨Bitwise Complement
-> The Bitwise Complement(NOT) inverts the bits in a single binary number.
Symbol- '~' (for C++, Java, Python, JavaScrpit)
✨Bitwise Left-Shift
-> The Bitwise left shift moves all bits in the number to the left and fills vacated bit position with 0.
Overflow- if after the left shifting total number of bits exceeds the range, then MSB is discarded. This condition is called overflow.
✨More about Bitwise Left-Shift and example
-> if a number n is left-shifted I times then result in number x:
x=n*(2*i)
Caution:- This formula does not hold in case of an overflow condition.
✨Bitwise Right-Shift
-> The Bitwise right shift moves all the bits in the number to right and LSB gets discarded.
If the number is unsinged then vacated position gets filled by 0. It is always advised to not use the right shift in signed numbers.
✨More about Bitwise Right-Shift and example
-> if a number n is right-shifted I times then result in number x:
x=floor(n/(2*i))
I hope this thread was helpful. If you liked it make sure you like it and retweet the first tweet so that it can help others too.
✨Coding interviews are majorly focused on data structures and algorithms but many times CS fundamental subjects also have been asked in interviews
Which are these topics ??????
👇Check out!!!
1️⃣Object-Oriented Programming
-->Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic
-->Insertion sort divides the given list into 2 parts.
-->The sorted part of the list at the beginning of the list and the unsorted part of the list at the end of the list.
-->It starts with the assumption that a list with a single element is always sorted.
-->So, insertion sort takes (length of list-1) iterations.
-->During each iteration, the first element of the unsorted list is picked and placed at the correct position of the sorted list. After all, iterations are done, the list gets sorted.
✨5 Algorithms you should learn if you are preparing for data structures and algorithm-based coding interviews
👇A Thread
1️⃣ kadane's algorithm
Problem statement-
Write an efficient algorithm to find the sum of contiguous subarray within a one-dimensional array of numbers that has the largest sum.