       char <- chars do
     digit = char + diff
 
-    defp count_digits_nosign(<<unquote(char), rest::binary>>, base, count)
+    defp count_digits_nosign(<<unquote(char), rest::bits>>, base, count)
          when base > unquote(digit) do
       count_digits_nosign(rest, base, count + 1)
     end
   end
 
-  defp count_digits_nosign(<<_::binary>>, _, count), do: count
+  defp count_digits_nosign(<<_::bits>>, _, count), do: count
 
   # TODO: Remove Integer.to_string/1 once the minimum supported version is
   #       Erlang/OTP 22, since it is covered by the now BIF Integer.to_string/2.

    raise ArgumentError, "invalid base #{inspect(base)}"
  end

  def parse(binary, base) do
    case count_digits(binary, base) do
      0 ->
        :error

    end
  end

  defp count_digits(<<sign, rest::bits>>, base) when sign in '+-' do
    case count_digits_nosign(rest, base, 1) do
      1 -> 0
      count -> count
    end
  end

  defp count_digits(<<rest::bits>>, base) do
    count_digits_nosign(rest, base, 0)
  end

