The task:

Write a program that allows you to enter two long type numbers from the keyboard, find and display their sum using bit operations to make it so that 20, 10, 5 and 2 bits are 0, and 18, 8, 0 - 1, the rest kept their values ​​and display the result.

    1 answer 1

    long num1, num2; cin >> num1 >> num2; long sum = num1 + num2; cout << sum << endl; long mask1 = (1l << 20) | (1l << 10) | (1l << 5) | (1l << 2); sum &= ~mask1; long mask2 = (1l << 18) | (1l << 8) | 1l; sum |= mask2; cout << sum << endl; 
    • 6
      It would be better for a person to ask what he tried, what did not work out. What else is the point?) - Costantino Rupert
    • 2
      It seems to me easier in this case to figure out how bit operations work - by dzhioev
    • It is not clear what 1l means in the code. Either small L, or capital I, or то. I ask you to correct .... Ps I look from the phone, I can’t copy it in the editor ... It’s better to write as clearly as possible right away. - gecube
    • geocube: and how do you suggest I do this? - dzhioev
    • why bother l? in my opinion 1 he is in Africa 1 - insolor