int2bin#

sionna.phy.fec.utils.int2bin(num: int | torch.Tensor, length: int) List[int] | torch.Tensor[source]#

Converts an integer or integer tensor to binary representation.

When num is a plain Python int, returns a list of 0’s and 1’s padded to the specified length. When num is a torch.Tensor, returns a tensor with an additional dimension of size length at the end.

Both num (or all elements) and length must be non-negative.

Parameters:
  • num (int | torch.Tensor) – The integer(s) to convert. Either a non-negative Python int or a torch.Tensor of integers.

  • length (int) – The desired bit length of the binary representation. Must be non-negative.

Outputs:

result – A list of 0’s and 1’s if num is an int, or a torch.Tensor with an extra trailing dimension of size length.

Examples

from sionna.phy.fec.utils import int2bin

# From a Python int
result = int2bin(5, 4)
print(result)
# [0, 1, 0, 1]

# From a PyTorch tensor
import torch
result = int2bin(torch.tensor([5, 12]), 4)
print(result)
# tensor([[0, 1, 0, 1],
#         [1, 1, 0, 0]])