You have been given a code snippet which contains an unfinished function represented by a pair of parentheses. You need to complete the function implementation in order to achieve a specific task. Implement the function so that it performs the following:

The function should take an integer as input and return another integer as output. The input integer represents a binary number. Your task is to count the number of consecutive 1s in the binary representation and return the maximum count.

For example, given the input 1101101, which is the binary representation of 109, the function should return 2 since there are two consecutive 1s in the binary representation.

Complete the function that solves the task.

```python
def count_consecutive_ones(n: int) -> int:
    pass
```
user
Sure, here's how you could implement this function in Python:

```python
def count_consecutive_ones(n: int) -> int:
    binary_n = bin(n)[2:]  # convert integer to binary string, starting from the second character
    max_count = 0
    current_count = 0
    for digit in binary_n:
        if digit == '1':
            current_count += 1
        else:
            max_count = max(max_count, current_count)
            current_count = 1
    return max(max_count, current_count)
```

This function converts the input integer to a binary string using the `bin()` function, then iterates through each digit in the string. If it's a "1", it adds it to the current count. Otherwise, it checks whether the current count is greater than the maximum count so far and returns the max. If not, it resets the current count to 1. Finally, it returns the maximum count including the current count, in case there's still one "1" at the end.
assistant
You have been given a code snippet which contains an unfinished function represented by a pair of parentheses. You need to complete the function implementation in order to achieve a specific task. Implement the function so that it performs the following:

The function should take an integer as input and return another integer as output. The input integer represents a binary number. Your task is to count the number of consecutive 1s in the binary representation and return the maximum count.

For example, given the input 1101101, which is the binary representation of 109, the function should return 2 since there are two consecutive 1s in the binary representation.

Complete the function that solves the task.

```python
def count_consecutive_ones(n: int) -> int:
    pass
```
user
Sure, here is the implementation of the function in Python:

```python
def count_consecutive_ones(n: int) -> int:
    binary_str = bin(n)[2:]  # convert integer to binary string
    max_count = 0
    current_count = 0
    for digit in binary_str:
        if digit == '1':
            current_count += 1
            max_count = max(max_count, current_count)
        else:
            current_count = 0
    return max_count
```

This function works by converting the input integer to a binary string, then iterating over the string. If the current digit is '1', it increments a counter and updates the maximum count. If the current digit is '0', it resets the counter. At the end, it returns the maximum count.
assistant