Decimal to binary Converter

This utility provides a module convert a integer number of a numpy array of integers to binary.

When input ia a Scalar:

num     = 5 # number to be converted to binary
numBits = 4
bits = Decimal2Binary()(num,numBits)

print(bits)
print(bits.shape)
[0 1 0 1]
(4,)

When input ia a Vector:

num     = 5
numBits = 4

bits = Decimal2Binary()(num,numBits)

print(bits)
print(bits.shape)
[[0 0 0 0]
 [0 0 0 1]
 [0 0 1 0]
 [0 0 1 1]
 [0 1 0 0]
 [0 1 0 1]
 [0 1 1 0]
 [0 1 1 1]
 [1 0 0 0]
 [1 0 0 1]
 [1 0 1 0]
 [1 0 1 1]
 [1 1 0 0]
 [1 1 0 1]
 [1 1 1 0]
 [1 1 1 1]]
(16, 4)

The details about the input-output interface of the Mapper modules is provided below.

class toolkit5G.Utils.Decimal2Binary[source]

This module converts an integer or NumPy array of integers to binary arrays. The representation of the binary number is right:output[…,-1] (LSB) to left:output[…,0] (MSB).

Warning

All values of inputs must be smaller than \(2^{numBits}-1\).

Parameters:

None

Input:
  • inputs (integer or Numpy array of integers) – Decimal(Integer) inputs to be converted to binary. It can be either an integer or an array of integers.

  • numBits (integer) – Defines the number of bits used for binary repersentation of each inputs.

Output:

(…,numBits), np.int8

Binary representation of inputs.

  • If inputs is integer, then output will be an array of size (numBits,).

  • If inputs is integer NumPy array of size K, then output will be an array of size (K,numBits).

Important

The representation of the binary number is right to left which implies that first element of each row of the element denotes the Most Significant Bit (MSB) and last element in each row of the output denote the Least significant bit (LSB).

Raises:
  • Exception – [Error-Decimal2Binary]: ‘inputs’ should be an integer or an array!

  • ValueError – [Error-Decimal2Binary]: All values of inputs must be smaller than 2**numBits-1!

  • Exception – [Error-Decimal2Binary]: ‘numBits’ should be a scalar integer!