+ 2
can you give me some resources for bits operations ?
I have been solving questions in order to learn new concepts and encountered the following on https://codeforces.com/group/MWSDmqGsZm/contest/326175/problem/F yet i have to be able to change the number provided by the user to 32 bits format and I need to add bits together I searched for bits operations and how to change a num to 32 bits format in cpp yet did not find a clear resource to learn about them,
6 Answers
+ 4
All numbers are stored by the computer in binary format. They are just displayed as decimals because it is easier for humans to understand them.
You can get the bits starting from the end, by taking the last digit modulo 2 (remainder after division by 2), and then actually divide it by two to continue, until the number reaches 0.
You can read about binary operators here:
https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/
There are some ideas how the number can be converted to binary representation, here:
https://www.techiedelight.com/convert-a-decimal-to-binary-in-cpp/
The task you linked, is actually a binary XOR operation. You can test this:
printf("4 ^ 6 = %d", 4 ^ 6); // result is 2
The true addition would be:
4 = 0100
+ 6 = 0110
=10 = 1010
1010 in binary is 1x8 + 0*4 + 1*2 + 0*1 = 10 in decimal. The mistake is made in the third bit from the right, there 1 + 1 = 2 but 2 is not a valid digit in binary, so this bit will be 0 and the 1 should be carried over to the left. If you remember in math, how you learned doing addition on paper, you'll understand.
+ 3
Tibor Santa
Thx so much the explanation is really clear and straight to the point , i have learnt alot.
+ 1
Ash[ā¤ļøāš„š¹ā¤ļøāš„] thx for you time any kind of help is appreciated i will be sure to check this out today or tommorrow and learn from it
+ 1
Ash[ā¤ļøāš„š¹ā¤ļøāš„] i have watched the first playlist and implemented it ( it was totaly worth it thx again lol) ,for now i think i am going to make a new post with the things that i learnt and their explanation in order to share the knowledge, ask how to improve some of the things that i wrote to learn new stuff and after that view the other link .