190. Reverse Bits

Input: n = 00000010100101000001111010011100
Output: 964176192 (00111001011110000010100101000000)
Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
Input: n = 11111111111111111111111111111101
Output: 3221225471 (10111111111111111111111111111111)
Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
class Solution:
def reverseBits(self, n: int) -> int:
res=0
for i in range(0,32):
res<<=1
res|=(n&1)
n>>=1
return res

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Deploy an AngularJS Conference App in 3 Steps

Frequency Counter Solving Pattern

From imperative to functional JavaScript

The Ultimate Vue Cheat Sheet for Version 3 and 2

Create a custom cartridge in SFRA (Salesforce Commerce Cloud) using sgmf-scripts

Node JS : Authentication and Authorization

Day 64 Training at Ryaz: Class based components.

Using JavaScript methods to update Chart.js data

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

From university student to technology lead – some thoughts

389. Find the Difference

Designing a Circular Buffer

Choose Your Messages

Bumble vs. Coffee Meets Bagel