Reverse bits in 32-bit int
Java
Hard
5 views
Problem Description
Task: reverse bits of int and return result.
Output Format
Return value
Constraints
Use loop 32 steps.
Official Solution
static int reverseBits(int x){int r=0;for(int i=0;i<32;i++){r=(r<<1)|(x&1);x>>>=1;}return r;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!