Repository: PennyLaneAI/pennylane

Issue:
int to qml.BasisEmbedding
### Feature details

Currently, to use `BasisEmbedding` we have to pass a list with the bits [0,1,0,0] for example to put a PauliX gate in the second qubit. It would be nice to be able to pass an integer number like:

```python
qml.BasisEmbedding(4, wires = range(4))
```
This result would be the same that:

```python
qml.BasisEmbedding([0,1,0,0], wires = range(4))
```
because 0100 is the number 4 in binary (note that PennyLane uses the convention $|q_0,q_1,\dots,q_{N-1}\rangle$ where $q_0$ is the most significant bit).

This feature have a lot of applications, for example for qRAMs where we could do things like this one:

```python
for i in range(16):
      qml.BasisEmbedding(i, wires = range(4))
     ### some stuff here
```

### Implementation

I'm using this functions to translate the integer to the list:

```python
def list_d(num, n_wires):

    mods = []
    while num != 0 or len(mods) != n_wires:
        mods.insert(0, num % 2)
        num //= 2

    return mods
```

```
list_d(4,5)
>>> [0,0,1,0,0]
```

Probably incorporating this routine will be enough. However, some checks should be added because if num > 2^n_wires, the code will fail.


### How important would you say this feature is?

1: Not important. Would be nice to have.

### Additional information

Make sure that the order of the list is the same as Pennylane. 
There are places where it is written from top to bottom and vice versa.


Discussion:
Hi, I'd like to do this.
Great! Thanks @tal66 😄
Let me know if you have any problem

Resolving patch:
diff --git a/pennylane/templates/embeddings/basis.py b/pennylane/templates/embeddings/basis.py
--- a/pennylane/templates/embeddings/basis.py
+++ b/pennylane/templates/embeddings/basis.py
@@ -23,8 +23,8 @@
 class BasisEmbedding(Operation):
     r"""Encodes :math:`n` binary features into a basis state of :math:`n` qubits.
 
-    For example, for ``features=np.array([0, 1, 0])``, the quantum system will be
-    prepared in state :math:`|010 \rangle`.
+    For example, for ``features=np.array([0, 1, 0])`` or ``features=2`` (binary 10), the
+    quantum system will be prepared in state :math:`|010 \rangle`.
 
     .. warning::
 
@@ -72,6 +72,10 @@ def circuit(feature_vector):
 
     def __init__(self, features, wires, do_queue=True, id=None):
 
+        if isinstance(features, int):
+            bin_string = f"{features:b}".zfill(len(wires))
+            features = [1 if d == "1" else 0 for d in bin_string]
+
         wires = Wires(wires)
         shape = qml.math.shape(features)
 
@@ -80,7 +84,9 @@ def __init__(self, features, wires, do_queue=True, id=None):
 
         n_features = shape[0]
         if n_features != len(wires):
-            raise ValueError(f"Features must be of length {len(wires)}; got length {n_features}.")
+            raise ValueError(
+                f"Features must be of length {len(wires)}; got length {n_features} (features={features})."
+            )
 
         features = list(qml.math.toarray(features))
 


Test patch:
diff --git a/tests/templates/test_embeddings/test_basis.py b/tests/templates/test_embeddings/test_basis.py
--- a/tests/templates/test_embeddings/test_basis.py
+++ b/tests/templates/test_embeddings/test_basis.py
@@ -76,7 +76,20 @@ def circuit2():
 class TestInputs:
     """Test inputs and pre-processing."""
 
-    @pytest.mark.parametrize("x", [[0], [0, 1, 1]])
+    @pytest.mark.parametrize(
+        ("feat","wires","expected"),
+        [(7, range(3), [1, 1, 1]), (2, range(4), [0, 0, 1, 0]), (8, range(5), [0, 1, 0, 0, 0])],
+    )
+    def test_features_as_int_conversion(self, feat, wires, expected):
+        """checks conversion from features as int to a list of binary digits
+           with length = len(wires)"""
+
+        assert (
+            qml.BasisEmbedding(features=feat, wires=wires).hyperparameters["basis_state"]
+            == expected
+        )
+
+    @pytest.mark.parametrize("x", [[0], [0, 1, 1], 4])
     def test_wrong_input_bits_exception(self, x):
         """Checks exception if number of features is not same as number of qubits."""