Example #1
0
 public void GetBitPositions_Must_ReturnTheRightBitPositions()
 {
     CollectionAssert.AreEqual(
         expected: new List <int> {
         4, 5
     },
         actual: BitService.GetBitPositions(new List <char> {
         '0', '0', '0', '0', '1', '1', '0', '0'
     }, '1').ToList(),
         message: "The result is not the expected");
 }
Example #2
0
        public IEnumerable <int> Count(int input)
        {
            try
            {
                _bitService.ValidateInput(input);

                var arrayOfBits = _bitService.ConvertToBitArray(input);

                // IN CASE OF NEED TO GET THE OCCURRENCES OF '0' it's possible
                var bitOccurrences = _bitService.GetBitOccurrences(arrayOfBits, '1');

                var reversedArrayOfBits = _bitService.ReverseBitArray(arrayOfBits);

                // IN CASE OF NEED TO GET THE POSITIONS OF '0' it's possible
                var bitPositions = _bitService.GetBitPositions(reversedArrayOfBits, '1');

                return(_bitService.GetCountingBitsOutput(bitOccurrences, bitPositions));
            }
            catch (Exception ex)
            {
                _loggerService.Error("Problem on Counting Bits for '${input}'", ex);
                throw ex;
            }
        }