> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/v6.0.0/llms.txt

# Function encode_fields_as_bytes

Module: `noir_aztec::utils::conversion::fields_as_bytes`

```rust
pub fn encode_fields_as_bytes<let N: u32>(fields: [Field; N]) -> [u8; N * 32]
```

Encodes an array of fields as bytes.

Losslessly preserves any field value; use [`try_decode_fields_from_bytes`](/aztec-nr-api/v6.0.0/noir_aztec/utils/conversion/fields_as_bytes/fn.try_decode_fields_from_bytes.md) to recover the original fields.

## Encoding

Each field is written as 32 big-endian bytes and the chunks are concatenated. The field array `[5, 42]` becomes:

```text
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,  // First field (32 bytes)
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42] // Second field (32 bytes)
```

## Privacy

The BN254 modulus is `< 2^254`, so every 32-byte chunk has its top bit at zero and the next bit biased. The output is therefore distinguishable from uniform random bytes; take this into account when feeding it into anything that assumes uniform randomness (e.g. ciphertexts meant to look random).
