`{"id":"620df0c3-3b80-4b26-983e-bf5f5c8356da","name":"Copy Set Bits In A Range","description":"1. You are given two numbers A and B.\r\n2. You are given two more numbers left and right, representing a range [left,right].\r\n3. You have to set bits in B which are set in A lying in the above mentioned range.\r\n4. Print the updated number B.","inputFormat":"4 numbers representing A,B,left and right.","outputFormat":"A number","constraints":"-10^9 &lt;= A,B &lt;= 10^9\r\n1 &lt; left &lt; right &lt; 32","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nint main(){\n int a, b, left, right;\n cin>>a>>b>>left>>right;\n //write your code here\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int a = scn.nextInt();\r\n int b = scn.nextInt();\r\n int left = scn.nextInt();\r\n int right = scn.nextInt();\r\n\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n13\r\n2\r\n3","sampleOutput":"15","questionVideo":"https://www.youtube.com/embed/v7pUZw-ZOYU?end=125","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"a62dd05a-0740-445c-9825-7ab4fa343c20","name":"Copy Set Bits In A Range","slug":"copy-set-bits-in-a-range","type":1}],"next":{"id":"f114f02b-ace2-47f6-8b38-84a9003b511f","name":"Copy Set Bits In a Range MCQ","type":0,"slug":"copy-set-bits-in-a-range-mcq"},"prev":{"id":"da53a616-d89e-4f19-9e9a-d1ca4f864765","name":"Flip Bits To Convert A To B","type":3,"slug":"flip-bits-to-convert-a-to-b"}}}`

Copy Set Bits In A Range

1. You are given two numbers A and B. 2. You are given two more numbers left and right, representing a range [left,right]. 3. You have to set bits in B which are set in A lying in the above mentioned range. 4. Print the updated number B.

`{"id":"620df0c3-3b80-4b26-983e-bf5f5c8356da","name":"Copy Set Bits In A Range","description":"1. You are given two numbers A and B.\r\n2. You are given two more numbers left and right, representing a range [left,right].\r\n3. You have to set bits in B which are set in A lying in the above mentioned range.\r\n4. Print the updated number B.","inputFormat":"4 numbers representing A,B,left and right.","outputFormat":"A number","constraints":"-10^9 &lt;= A,B &lt;= 10^9\r\n1 &lt; left &lt; right &lt; 32","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nint main(){\n int a, b, left, right;\n cin>>a>>b>>left>>right;\n //write your code here\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int a = scn.nextInt();\r\n int b = scn.nextInt();\r\n int left = scn.nextInt();\r\n int right = scn.nextInt();\r\n\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n13\r\n2\r\n3","sampleOutput":"15","questionVideo":"https://www.youtube.com/embed/v7pUZw-ZOYU?end=125","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"a62dd05a-0740-445c-9825-7ab4fa343c20","name":"Copy Set Bits In A Range","slug":"copy-set-bits-in-a-range","type":1}],"next":{"id":"f114f02b-ace2-47f6-8b38-84a9003b511f","name":"Copy Set Bits In a Range MCQ","type":0,"slug":"copy-set-bits-in-a-range-mcq"},"prev":{"id":"da53a616-d89e-4f19-9e9a-d1ca4f864765","name":"Flip Bits To Convert A To B","type":3,"slug":"flip-bits-to-convert-a-to-b"}}}`

Editor

Loading...

Copy Set Bits In A Range

easy

1. You are given two numbers A and B. 2. You are given two more numbers left and right, representing a range [left,right]. 3. You have to set bits in B which are set in A lying in the above mentioned range. 4. Print the updated number B.

Constraints

-10^9 <= A,B <= 10^9 1 < left < right < 32

Format

Input

4 numbers representing A,B,left and right.

A number

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}10 13 2 3```

Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}15`

Question Video

Discussions

Show Discussion

Related Resources