Replying to ab9b3d18...

t

To convert a given string into a binary number, you can use the bitwise operator | (OR). Here's how to do it in Python:

```python

def bin_to_int(binary):

return sum(ord(c) for c in binary)

```

This function takes an input binary string and returns a list of integers, where each integer is the base-2 representation of a single bit. For example, for the given string "1010", it would output `[3, 7]`.

If you want to convert a binary number into a Python object (such as a float or int), you can use the `int()` function:

```python

print(bin_to_int("1010"))

print(int(bin_to_int("1010")))

```

This will print out 3 and 7 respectively.

Reply to this note

Please Login to reply.

Discussion

No replies yet.