`{"id":"47394afb-cf10-47aa-a077-312ea966d021","name":"Print Binary And Reverse Bits","description":"1. You are given a number.\r\n2. You have to print its binary representation.\r\n3. You also have to reverse the bits of n and print the number obtained after reversing the bits.","inputFormat":"A number n","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\n using namespace std;\n int main(){\n int n;\n cin>>n;\n // write your code here\n \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 n = scn.nextInt();\r\n \r\n //write your code here\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11","sampleOutput":"1011\r\n13\r\n","questionVideo":"https://www.youtube.com/embed/TC7nCh1MZM8?end=43","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":"de957366-b10a-4314-955f-d466cdb454ae","name":"Print Binary And Reverse Bits","slug":"print-binary-and-reverse-bits","type":1}],"next":{"id":"30f8ddaf-2143-4819-9806-3ce69df1c56e","name":"Print Binary And Reverse MCQ","type":0,"slug":"print-binary-and-reverse-mcq"},"prev":{"id":"b3b2fa41-048e-4050-a7da-c3f1f35fc781","name":"COUNT SET BITS IN FIRST N NATURAL NUMBERS","type":3,"slug":"count-set-bits-in-first-n-natural-numbers"}}}`

# Print Binary And Reverse Bits

1. You are given a number. 2. You have to print its binary representation. 3. You also have to reverse the bits of n and print the number obtained after reversing the bits.

`{"id":"47394afb-cf10-47aa-a077-312ea966d021","name":"Print Binary And Reverse Bits","description":"1. You are given a number.\r\n2. You have to print its binary representation.\r\n3. You also have to reverse the bits of n and print the number obtained after reversing the bits.","inputFormat":"A number n","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\n using namespace std;\n int main(){\n int n;\n cin>>n;\n // write your code here\n \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 n = scn.nextInt();\r\n \r\n //write your code here\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"11","sampleOutput":"1011\r\n13\r\n","questionVideo":"https://www.youtube.com/embed/TC7nCh1MZM8?end=43","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":"de957366-b10a-4314-955f-d466cdb454ae","name":"Print Binary And Reverse Bits","slug":"print-binary-and-reverse-bits","type":1}],"next":{"id":"30f8ddaf-2143-4819-9806-3ce69df1c56e","name":"Print Binary And Reverse MCQ","type":0,"slug":"print-binary-and-reverse-mcq"},"prev":{"id":"b3b2fa41-048e-4050-a7da-c3f1f35fc781","name":"COUNT SET BITS IN FIRST N NATURAL NUMBERS","type":3,"slug":"count-set-bits-in-first-n-natural-numbers"}}}`

Editor

# Print Binary And Reverse Bits

easy

1. You are given a number. 2. You have to print its binary representation. 3. You also have to reverse the bits of n and print the number obtained after reversing the bits.

1 <= n <= 10^9

## Format

A number n

### Output

Check the sample ouput and question video.

## 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;}11`

### 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;}1011 13 ```

Question Video

Discussions

Show Discussion

Related Resources