Nihar Profile picture
Jan 28, 2022 16 tweets 4 min read Read on X
Bit-manipulation is confusing. not anymore!

Learn bitwise operator just by reading this-

A thread👇
✨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.

Also, follow me
@Nihar_Thummar
About me

I'm Nihar 👋
I am a student and a developer.
I talk about
-🐍Python
-💻Data structures and algorithm
-🚀WEB 3
-🛠️Build in Public
If you found any mistakes please let me know! Also if you have any questions feel free to ask in comment !

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Nihar

Nihar Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Nihar_Thummar

Apr 20, 2022
✨Roadmap to learn DSA in 2022

👇check out
1️⃣Learn a programming language

->choose from C++, Java or python only.

->There are huge communities and lots of resources in C++ and Java so going with one of them will help you!
2️⃣Build basic problem solving

->For this go to the hacker-rank algorithms section and solve questions with tags of warm-up and implementation!

hackerrank.com/domains/algori…
Read 8 tweets
Apr 18, 2022
✨𝗕𝗜𝗧𝗖𝗢𝗜𝗡 𝘃𝘀 𝗘𝗧𝗛𝗘𝗥𝗘𝗨𝗠 --The difference should be clear!!

👇Read out Image
✨𝗙𝗢𝗨𝗡𝗗𝗔𝗧𝗜𝗢𝗡

-->Bitcoin is the first and the biggest (according to market cap) cryptocurrency. Bitcoin was introduced in 2009.

-->Ethereum is a far recent blockchain that was introduced in 2015.
✨𝗨𝗧𝗜𝗟𝗜𝗧𝗬

-->Bitcoin blockchain can simply be pictured as a database of accounts and ledger of transactions.

-->Ethereum blockchain can store computer codes (known as smart contracts) which allow users to build D-Apps on it!
Read 8 tweets
Mar 29, 2022
✨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
✨Resources to learn OOPs

C++ :-

Java:-youtube.com/playlist?list=… youtube.com/playlist?list=…

Python :-

Interview Questions:- javatpoint.com/oops-interview…
Read 11 tweets
Mar 27, 2022
✨Learn algorithm

⚡INSERTION SORT

👇read out
-->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.
Read 10 tweets
Mar 25, 2022
✨Python tricks

👇Check out
1️⃣In-Place Swapping Of Two Numbers Image
2️⃣Reversing a string in Python Image
Read 12 tweets
Feb 28, 2022
✨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.

Further read:- medium.com/@rsinghal757/k… Image
2️⃣Floyd's Tortoise and Hare Algorithm

Problem Statement-
Given a linked list, determine if it has a cycle in it.

Further read:-dev.to/alisabaj/floyd… Image
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(