C# no bit manipulation


  • 0
    public class Solution {
        public uint reverseBits(uint n) {
            string binary = Convert.ToString(n, 2);
                int length = binary.Length;
                if(length < 32)
                {
                    for(int i = 0;i<(32 - length);i++)
                    {
                        binary = binary.Insert(0, "0");
                    }
                }
                string reverse = "";
                for (int i = binary.Length - 1; i >= 0; i--)
                {
                    reverse += binary[i].ToString();
                }
                return (uint)Convert.ToInt64(reverse, 2);
            
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.