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
numis a plain Python int, returns a list of 0’s and 1’s padded to the specifiedlength. Whennumis a torch.Tensor, returns a tensor with an additional dimension of sizelengthat the end.Both
num(or all elements) andlengthmust 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
numis an int, or a torch.Tensor with an extra trailing dimension of sizelength.
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]])