< Summary

Information
Class: LeetCode.Algorithms.ReverseBits.ReverseBitsDivideAndConquer
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ReverseBits\ReverseBitsDivideAndConquer.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 39
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ReverseBits(...)100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ReverseBits\ReverseBitsDivideAndConquer.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.ReverseBits;
 13
 14/// <inheritdoc />
 15public sealed class ReverseBitsDivideAndConquer : IReverseBits
 16{
 17    private const int Mask1 = 0x55555555;
 18    private const int Mask2 = 0x33333333;
 19    private const int Mask4 = 0x0F0F0F0F;
 20    private const int Mask8 = 0x00FF00FF;
 21    private const int Mask16 = 0x0000FFFF;
 22
 23    /// <summary>
 24    ///     Time complexity - O(1)
 25    ///     Space complexity - O(1)
 26    /// </summary>
 27    /// <param name="n"></param>
 28    /// <returns></returns>
 29    public int ReverseBits(int n)
 230    {
 231        n = ((n >> 1) & Mask1) | ((n & Mask1) << 1);
 232        n = ((n >> 2) & Mask2) | ((n & Mask2) << 2);
 233        n = ((n >> 4) & Mask4) | ((n & Mask4) << 4);
 234        n = ((n >> 8) & Mask8) | ((n & Mask8) << 8);
 235        n = ((n >> 16) & Mask16) | ((n & Mask16) << 16);
 36
 237        return n;
 238    }
 39}

Methods/Properties

ReverseBits(System.Int32)