bin2int#
- sionna.phy.fec.utils.bin2int(arr: List[int] | torch.Tensor) int | None | torch.Tensor[source]#
Converts a binary array or tensor to its integer representation.
Interprets the binary representation from most significant to least significant bit. For example,
[1, 0, 1]is converted to5.Accepts both plain Python lists and PyTorch tensors. When a list is provided, returns a plain Python int (or None if empty). When a tensor is provided, returns a tensor with the last dimension reduced.
- Parameters:
arr (List[int] | torch.Tensor) – An iterable of binary values (0’s and 1’s), or a torch.Tensor with binary values along the last dimension.
- Outputs:
result – The integer representation. A plain int if
arris a list, None if the list is empty, or a torch.Tensor ifarris a tensor.
Examples
from sionna.phy.fec.utils import bin2int # From a Python list result = bin2int([1, 0, 1]) print(result) # 5 # From a PyTorch tensor import torch result = bin2int(torch.tensor([[1, 0, 1], [0, 1, 1]])) print(result) # tensor([5, 3])