# evm_signextend

Implements EVM SIGNEXTEND. Byte k is indexed from the least significant byte; bit 8*k+7 is copied through all higher bits. SQL BIGINT k values below 0 or at least 31 return the unchanged UINT256 word. NULL input propagates to NULL.

Canonical HTML: <https://determica.com/docs/functions/evm_signextend>

- Kind: scalar function
- Category: [EVM utilities](/docs/category/evm-utilities.md)
- Tags: Types, EVM

Implements EVM SIGNEXTEND. Byte k is indexed from the least significant byte; bit 8*k+7 is copied through all higher bits. SQL BIGINT k values below 0 or at least 31 return the unchanged UINT256 word. NULL input propagates to NULL.

## Overload 1: evm_signextend(BIGINT, UINT256)

```sql
evm_signextend(BIGINT, UINT256)
```

Sign-extends the low k+1 bytes of a UINT256 EVM word.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `k` (BIGINT; required; positional) — BIGINT index from the least significant byte.
- `x` (UINT256; required; positional) — UINT256 word to sign-extend.

### Returns

Sign-extended word

UINT256 word with high bits filled from bit 8*k+7, or NULL for NULL input.

- `result` (UINT256)

Sign-extended word. UINT256 word with high bits filled from bit 8*k+7, or NULL for NULL input.

### Examples

_Local SQL · Local_

```sql
SELECT evm_signextend(0::BIGINT, '0x80'::UINT256)::VARCHAR AS result;
-- => [{"result":"115792089237316195423570985008687907853269984665640564039457584007913129639808"}]
```
