can you give me some resources for bits operations ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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,

14th Jul 2023, 8:43 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
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.
14th Jul 2023, 9:41 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Tibor Santa Thx so much the explanation is really clear and straight to the point , i have learnt alot.
14th Jul 2023, 9:50 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 3
Thanks for the info about this group it would be a nice collection of bitwise related problems from basic level i g Anyways though I am unable to find any written very brief resource upon it but I knew where it had been taught very nicely and intuitively ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡ https://www.youtube.com/playlist?list=PLQXZIFwMtjozwj9qF3h-1pF1kAcUzFya0 https://www.youtube.com/live/XLahS5d_eGU?feature=share Hope it helps
15th Jul 2023, 11:12 AM
Manuphile
Manuphile - avatar
+ 2
Dareen Moughrabi thanks to that prodigy of our land Bharat Singhla thank god he taught only in English ๐Ÿ˜‚๐Ÿ˜…
15th Jul 2023, 3:15 PM
Manuphile
Manuphile - avatar
+ 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
15th Jul 2023, 11:30 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 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 .
15th Jul 2023, 3:13 PM
Dareen Moughrabi
Dareen Moughrabi - avatar