---
title: std.strtol
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/strings/std-strtol
---

```
INTEGER std.strtol(STRING s, INTEGER base)
```

**Available in:** all subroutines

Converts the string `s` to an integer value. The value `base` must be a constant
integer expression, integer variable, or integer-returning function.

The following string formats are supported:

- Decimal (base 10) integer syntax. For example, `123`, `-4`.
- Hexadecimal (base 16) integer syntax. For example, `0xABC`, `-0x0`.
- Octal (base 8) integer syntax. For example, `0`, `0123`.

The syntax for integers extends the syntax for VCL INTEGER literals in base 10
and 16 respectively. See [VCL Types](https://www.fastly.com/documentation/reference/vcl/types/integer/) for details of
the INTEGER literal syntax for these bases.

Supported bases are 2 to 36, inclusive, and the special value 0. For bases over
10, the alphabetic digits are case insensitive.

A base of 0 causes the base to be automatically determined from the string
format. In this case, a `0x` prefix indicates hex (base 16), a prefix of `0`
indicates octal (base 8) and otherwise the base is taken as decimal (base 10).

When an explicit base is specified, the hexadecimal prefix of `0x` and the octal
prefix of `0` are not required.

Whitespace and trailing characters are permitted and have no effect on the
value produced.

## Errors

If the string could not be parsed, then
`fastly.error` will be set to `EPARSENUM`.
If the base is outside the permitted range, or if the numeric value would
cause overflow, then `fastly.error` will be
set to `ERANGE`.

## Example

```vcl
if (std.strtol(req.http.X-HexValue, 16) == 42) {
  set req.http.X-TheAnswer = "Found";
}
```
