Home Contents | # string.cvi | String | Core4 Lua Commands

## SYNOPSIS

1. value = string.cvi(s [, i [, j]])
2. value = string.cvin(s [, i [, j]])
3. value = string.cvl(s [, i [, j]])
4. value = string.cvln(s [, i [, j]])

## DESCRIPTION

The functions convert a substring into a binary value. All functions take a substring s[i], s[i+1], ···, s[j] as input.
The default value for i is 1; the default value for j is the number of characters in s.

string.cvi() returns the little-endian 16-bit value of the first two bytes of the substring. It is equivalent to string.byte(s, i) | (string.byte(s, i+1) << 8).

string.cvin() is the big endian variant of string.cvi(). It is equivalent to (string.byte(s, i) << 8) | string.byte(s, i+1).

string.cvn() returns the little-endian 32-bit value of the first four bytes of the substring. It is equivalent to string.byte(s, i) | (string.byte(s, i+1) << 8) | (string.byte(s, i+2) << 16) | (string.byte(s, i+3) << 24).

string.cvln() is the big endian variant of string.cvl(). It is equivalent to (string.byte(s, i) << 24) | (string.byte(s, i+1) << 16) | (string.byte(s, i+2) << 8) | string.byte(s, i+3).

## RETURN VALUE

All functions return a number or nil, if the (sub-)string is too short to decode.

## EXAMPLE

>
print(string.cvi("\x00\x01"))
256

## SEE ALSO

string.mki, string.mkin, string.mkl, string.mkln