# digits!

digits!(array, n, [base])

Fills an array of the digits of `n`

in the given base. More significant digits are at higher indexes. If the array length is insufficient, the least significant digits are filled up to the array length. If the array length is excessive, the excess portion is filled with zeros.

## Examples

```
julia> arr = [0, 0, 0];
julia> digits!(arr, 123, 10)
3-element Array{Int64,1}:
3
2
1
```

This example fills the array `arr`

with the decimal digits of the number 123. The most significant digit (3) is placed at index 1, followed by 2 at index 2, and 1 at index 3.

```
julia> digits!(arr, 456, 2)
3-element Array{Int64,1}:
0
1
0
```

In this example, the binary (base 2) representation of the number 456 is stored in the array `arr`

. The most significant digit (1) is placed at index 2, followed by 0 at index 2, and another 0 at index 3.

```
julia> digits!(arr, 789, 16)
3-element Array{Int64,1}:
13
14
11
```

Here, the hexadecimal (base 16) representation of the number 789 is stored in the array `arr`

. The most significant digit (13) is placed at index 1, followed by 14 at index 2, and 11 at index 3.

Common mistake example:

```
julia> arr = [0];
julia> digits!(arr, 123, 10)
ERROR: BoundsError: attempt to access 1-element Array{Int64,1} at index [2]
```

In this example, the array `arr`

has insufficient length to store all the digits of the number. Make sure the array has enough capacity to hold the expected number of digits.

## See Also

Array, broadcast, cat, combinations, conj!, digits!, fieldnames, fill, fill!, last, length, maximum, minimum, ones, parent, parentindexes, partitions, permutations, pointer, pointer_to_array, promote_shape, rand!, reshape, scale, similar, sum, sum_kbn, takebuf_array, transpose!, vec, zeros,## User Contributed Notes

### Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.