---
title: bin.base64_to_hex
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/cryptographic/bin-base64-to-hex
---

```
STRING bin.base64_to_hex(STRING s)
```

**Available in:** all subroutines

This function converts the Base64-encoded string `s` into a hexadecimal sequence
of the same bytes. The hexadecimal sequence uses the symbols `"0"`–`"9"` to
represent the values 0 to 9, and `"A"`–`"F"` to represent the values 10 to 15.

`bin.base64_to_hex` always uses two hexadecimal digits to represent a binary
value even if the numeric value fits within one hexadecimal digit (0-F).
For example, `bin.base64_to_hex("AQ==")` is `"01"`.

If the Base64-encoded string `s` contains any null bytes, then
`bin.base64_to_hex` does not terminate and does not return a truncated
hexadecimal sequence. For example, `bin.base64_to_hex("AJ/CMw==")` is
`"009FC233"`.

If the Base64-encoded string `s` contains any non-alphabet characters, then
`bin.base64_to_hex` terminates and returns a _not set_ value. For example,
`bin.base64_to_hex("YWJ%jZA==")` is a _not set_ value.

If `bin.base64_to_hex` is called with a _not set_ value or with an empty string
argument, then it returns the string `""`. For example, `bin.base64_to_hex("")`
is  `""`.

To check if the return value is not an empty string or a _not set_ value, use
the `std.strlen()` function, which returns `0` in both cases.

```vcl
if (std.strlen(bin.base64_to_hex(req.http.Base64-Input)) > 0) {
    // Do something if the hexadecimal representation of the Base64-encoded
    // input string is not an empty string or a not set value.
}
```

## Errors

If the Base64-encoded string `s` is not valid Base64, then `fastly.error`
will be set to `EINVAL`.

## Examples

```vcl
bin.base64_to_hex("AQIDBAUGBwgJ") # returns "010203040506070809"
bin.base64_to_hex("AJ8AwgAzAA==") # returns "009F00C2003300"
bin.base64_to_hex("-YWJjZA==") # returns a not set value and fastly.error is "EINVAL"
bin.base64_to_hex("") # returns ""
bin.base64_to_hex(not set string) # returns a not set value
bin.base64_to_hex("YWJjZA==") # returns "61626364"
```
